View Javadoc
1   package org.woehlke.computer.kurzweil.tabs.dla.control;
2   
3   import org.woehlke.computer.kurzweil.tabs.dla.DiffusionLimitedAggregation;
4   import org.woehlke.computer.kurzweil.tabs.dla.model.Particles;
5   import org.woehlke.computer.kurzweil.tabs.dla.view.WorldCanvas;
6   
7   /**
8    * Diffusion Limited Aggregation.
9    *
10   * (C) 2006 - 2013 Thomas Woehlke.
11   * https://thomas-woehlke.blogspot.com/2016/01/diffusion-limited-aggregation.html
12   * @author Thomas Woehlke
13   *
14   * Date: 05.02.2006
15   * Time: 00:36:20
16   */
17  public class ControllerThread extends Thread
18          implements Runnable, DiffusionLimitedAggregation {
19  
20      static final long serialVersionUID = 242L;
21  
22  
23      private Particles particles;
24      private WorldCanvas canvas;
25  
26      private Boolean goOn;
27  
28      public ControllerThread(WorldCanvas canvas, Particles particles) {
29          goOn = Boolean.TRUE;
30          this.canvas=canvas;
31          this.particles=particles;
32      }
33  
34      public void run() {
35          boolean doIt;
36          do {
37              synchronized (goOn) {
38                  doIt = goOn.booleanValue();
39              }
40              particles.move();
41              canvas.repaint();
42              try { sleep(THREAD_SLEEP_TIME); }
43              catch (InterruptedException e) { e.printStackTrace(); }
44          }
45          while (doIt);
46      }
47  
48      public void exit() {
49          synchronized (goOn) {
50              goOn = Boolean.FALSE;
51          }
52      }
53  
54  
55  }