Your browser does not support JavaScript and this site utilizes JavaScript to build content and provide links to additional information. You should either enable JavaScript in your browser settings or use a browser that supports JavaScript in order to take full advantage of this site.
1 36 37 40 41 42 package java2d; 43 44 import java.awt.*; 45 46 47 50 public abstract class AnimatingSurface extends Surface implements Runnable { 51 52 public Thread thread; 53 54 public abstract void step(int w, int h); 55 56 public abstract void reset(int newwidth, int newheight); 57 58 59 public void start() { 60 if (thread == null && !dontThread) { 61 thread = new Thread (this); 62 thread.setPriority(Thread.MIN_PRIORITY); 63 thread.setName(name + " Demo"); 64 thread.start(); 65 } 66 } 67 68 69 public synchronized void stop() { 70 if (thread != null) { 71 thread.interrupt(); 72 } 73 thread = null; 74 notifyAll(); 75 } 76 77 78 public void run() { 79 80 Thread me = Thread.currentThread(); 81 82 while (thread == me && !isShowing() || getSize().width == 0) { 83 try { 84 thread.sleep(200); 85 } catch (InterruptedException e) { } 86 } 87 88 while (thread == me) { 89 repaint(); 90 try { 91 thread.sleep(sleepAmount); 92 } catch (InterruptedException e) { } 93 } 94 thread = null; 95 } 96 } 97
| Popular Tags
|