summaryrefslogtreecommitdiffstats
path: root/Master/Reference Architectures and Patterns/hjp5/examples/Listing3408.java
blob: 42c8f4f00bddf5c05f221f7351a8c7cb0a0056b0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/* Listing3408.java */

import java.awt.*;
import java.awt.event.*;

public class Listing3408
extends Frame
implements Runnable
{
  Thread th;
  Image[] arImg;
  int actimage;

  public static void main(String[] args)
  {
    Listing3408 wnd = new Listing3408();
    wnd.setSize(200,150);
    wnd.setVisible(true);
    wnd.startAnimation();
  }

  public Listing3408()
  {
    super("Bitmap-Folge");
    addWindowListener(new WindowClosingAdapter(true));
  }

  public void startAnimation()
  {
    th = new Thread(this);
    actimage = -1;
    th.start();
  }

  public void run()
  {
    //Bilder laden
    arImg = new Image[30];
    MediaTracker mt = new MediaTracker(this);
    Toolkit tk = getToolkit();
    for (int i = 1; i <= 30; ++i) {
      arImg[i-1] = tk.getImage("images/jana"+i+".gif");
      mt.addImage(arImg[i-1], 0);
      actimage = -i;
      repaint();
      try {
        mt.waitForAll();
      } catch (InterruptedException e) {
        //nothing
      }
    }
    //Animation beginnen
    actimage = 0;
    while (true) {
      repaint();
      actimage = (actimage + 1) % 30;
      try {
        Thread.sleep(50);
      } catch (InterruptedException e) {
        //nichts
      }
    }
  }

  public void paint(Graphics g)
  {
    if (actimage < 0) {
      g.drawString("Lade Bitmap "+(-actimage),10,50);
    } else {
      g.drawImage(arImg[actimage],10,30,this);
    }
  }
}