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