View Javadoc
1   package org.woehlke.computer.kurzweil.mandelbrot.control;
2   
3   import org.woehlke.computer.kurzweil.mandelbrot.model.ApplicationModel;
4   import org.woehlke.computer.kurzweil.mandelbrot.view.ApplicationFrame;
5   
6   /**
7    * Mandelbrot Set drawn by a Turing Machine.
8    *
9    * (C) 2006 - 2015 Thomas Woehlke.
10   * https://thomas-woehlke.blogspot.com/2016/01/mandelbrot-set-drawn-by-turing-machine.html
11   * @author Thomas Woehlke
12   *
13   * Date: 05.02.2006
14   * Time: 00:36:20
15   */
16  public class ControllerThread extends Thread implements Runnable {
17  
18      private volatile ApplicationModel applicationModel;
19      private volatile ApplicationFrame frame;
20  
21      private final int THREAD_SLEEP_TIME = 1;
22  
23      private volatile Boolean goOn;
24  
25      public ControllerThread(ApplicationModel model, ApplicationFrame frame) {
26          this.frame = frame;
27          this.applicationModel = model;
28          goOn = Boolean.TRUE;
29      }
30  
31      public void run() {
32          boolean doIt;
33          do {
34              synchronized (goOn) {
35                  doIt = goOn.booleanValue();
36              }
37              if(this.applicationModel.step()){
38                  frame.getCanvas().repaint();
39              }
40              try { sleep(THREAD_SLEEP_TIME); }
41              catch (InterruptedException e) { }
42          }
43          while (doIt);
44      }
45  
46      public void exit() {
47          synchronized (goOn) {
48              goOn = Boolean.FALSE;
49          }
50      }
51  
52  }