1:
2: import java.awt.*;
3:
4: public abstract class AnimationApplet
5: extends java.applet.Applet
6: implements java.lang.Runnable {
7: public void start() {
8: animationThread = new Thread(this);
9: animationThread.start();
10: }
11: public void stop() {
12: animationThread = null;
13: }
14: public void run() {
15: while (Thread.currentThread() == animationThread) {
16: try {
17: Thread.currentThread().sleep(delay);
18: } catch (InterruptedException e){}
19: repaint();
20: }
21: }
22: final public void setDelay(int delay) {
23: this.delay = delay;
24: }
25: final public int getDelay() {
26: return delay;
27: }
28: /** The animation thread */
29: protected Thread animationThread;
30: /** The interval between two consecutive frames
31: in milliseconds */
32: protected int delay = 100;
33: }