1import java.applet.Applet;
2import java.awt.*;
3
4
5
6public
7class MediaTrackerAnimation extends ImageAnimation {
8
9 MediaTracker tracker;
10
11
12
13 public
14 void init() {
15 super.init();
16
17
18
19
20 tracker = new MediaTracker(this);
21
22 for (int i = 0;
23 i < images.length;
24 ++i) {
25 tracker.addImage(images[i],i);
26 }
27 }
28
29
30
31 public
32 void run() {
33
34 while (Thread.currentThread() == animatorThread) {
35 currImage += direction;
36 if (currImage == images.length || currImage == -1) {
37 direction = -direction;
38 currImage += 2 * direction;
39 }
40
41
42
43
44
45 if ( ! tracker.checkID(currImage) ) {
46 try {
47 showStatus("wait for loading image" + currImage);
48 tracker.waitForID(currImage);
49 } catch (InterruptedException e) {
50 showStatus("MediaTracker error: " + e);
51 }
52 }
53
54
55
56 repaint();
57 sleepAWhile();
58 }
59 }
60}
61
62