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
8
9
10
11
12
13
14
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 }