示例#1
0
  /** Clear the current cells and replace with the indicated starting pattern. */
  public void reset(String patternName) {
    stop = true;
    int temp = generationMax;
    setGenerationCount(0);
    setMaxGenerations(0);
    if (patternName.equals("Random")) {
      theModel.reset(0.5);
    } else if (patternName.equals("R-Pentamino")) {
      theModel.reset(1);
    } else if (patternName.equals("Box")) {
      theModel.reset(2);
    } else if (patternName.equals("X Box")) {
      theModel.reset(3);
    }

    canvas.repaint();
    // runGenerations(); //* Replace this by appropriate use of a thread

    synchronized (canvas) {
      canvas.notifyAll();
      stop = false;
      canvas.repaint();
    }
    setMaxGenerations(temp);
    setGenerationCount(0);
  }
示例#2
0
  /** Set the number of generations the model will run */
  public void setMaxGenerations(int newMax) {
    changes = false;
    generationMax = newMax;
    if (!(generationCount < generationMax)) {
      changes = true;
    }
    setGenerationCount(generationCount);

    if (changes) {
      synchronized (canvas) {
        changes = false;
        canvas.repaint();
        canvas.notifyAll();
      }
    }
  }
示例#3
0
  public void run() {
    boolean done = false;

    while (!done) {
      synchronized (canvas) {
        while (generationCount < generationMax) {
          if (stop) {
            try {
              canvas.wait();
            } catch (InterruptedException e) {
            }
          }
          nextGeneration();
          canvas.repaint();
          canvas.notifyAll();
        }
      }
    }
  }