By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,657 Members | 1,045 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,657 IT Pros & Developers. It's quick & easy.

what package to import when there is board?

P: 50
hi all,
i'm trying out some examples on java..and i found this code where there is board and i cant find out what package to import to make this work, im getting error where there is "board"..
i have tried out the following but none worked:
import java.awt.*;
import javax.swing.*;
import java.util.*;
import java.applet.Applet;

plz help


Expand|Select|Wrap|Line Numbers
  1. import java.util.concurrent.CyclicBarrier;
  2.  
  3. public class CellularAutomata {
  4. private final Board mainBoard;
  5. private final CyclicBarrier barrier;
  6. private final Worker[] workers;
  7.  
  8. public CellularAutomata(Board board) {
  9.     this.mainBoard = board;
  10.  
  11.     int count = Runtime.getRuntime().availableProcessors();
  12.  
  13.     this.barrier = new CyclicBarrier(count, new Runnable() 
  14.     { // barrier action
  15.         public void run(){mainBoard.commitNewValues();
  16.         }
  17.         }
  18.     );
  19.     this.workers = new Worker[count];
  20.  
  21.     for (int i = 0; i < count; i++)
  22.         workers[i] = new Worker(mainBoard.getSubBoard(count, i));
  23.     } // constructor
  24.  
  25.     public void start() {
  26.         for (int i = 0; i < workers.length; i++)     
  27.             new Thread(workers[i]).start();
  28.         mainBoard.waitForConvergence();
  29. } // start()
  30. } // CellularAutomata
  31.  
  32.  
  33. class Worker implements Runnable {
  34.  
  35.     private final Board board;
  36.  
  37.     public Worker(Board board) { 
  38.         this.board = board; 
  39.         }
  40.  
  41.     public void run() {
  42.         while (!board.hasConverged()) {
  43.             for (int x = 0; x < board.getMaxX(); x++)
  44.                 for (int y = 0; y < board.getMaxY(); y++)
  45.                     board.setNewValue(x, y, computeValue(x, y));
  46.             try { barrier.await(); 
  47.             }
  48.             catch (InterruptedException ex) { return; }
  49.             catch (BrokenBarrierException ex) { return; }
  50.         } // while
  51.     } // run()
  52.  
  53.     private int computeValue(int x, int y) {
  54. // Compute the new value that goes in (x,y)
  55.  
  56. }
  57. } // Worker
  58.  
Jan 20 '09 #1
Share this Question
Share on Google+
1 Reply


Expert 10K+
P: 11,448
Board is certainly not a class that comes with your JSE distribution. I suggest you'd read that example again, maybe it's one of their classes and they have shown the source of that class.

kind regards,

Jos
Jan 20 '09 #2

Post your reply

Sign in to post your reply or Sign up for a free account.