Пример #1
0
  public void actionPerformed(ActionEvent ae) {

    if (ae.getSource() == this.buttonStart && !animate) {
      animate = true;
      animatorThread = new Thread(animator);
      animatorThread.start();
    }

    if (ae.getSource() == this.buttonStop && animate) {
      animate = false;
      animatorThread = null;
    }

    if (ae.getSource() == this.buttonNextRound && !animate) {
      board.nextRound();
      numOfGenerations++;
      grid.setBoard(board.getCurrentRound());
      grid.repaint();
      generationsLabel.setText("Generation " + numOfGenerations);
    }

    if (ae.getSource() == this.buttonClearBoard && !animate) {
      board.clear();
      this.numOfGenerations = 0;
      grid.repaint();
      generationsLabel.setText("Generation " + numOfGenerations);
    }

    if (ae.getSource() == this.drawingCheckBox) {
      draw = drawingCheckBox.isSelected();
    }
  }
Пример #2
0
        @Override
        public void run() {

          while (animate) {
            board.nextRound();
            grid.setBoard(board.getCurrentRound());
            numOfGenerations++;
            grid.repaint();
            generationsLabel.setText("Generation " + numOfGenerations);

            try {
              Thread.sleep(250);
            } catch (InterruptedException e) {
              e.printStackTrace();
            }
          }
        }