diff options
Diffstat (limited to 'Master/Reference Architectures and Patterns/hjp5/examples/Listing3408.java')
| -rw-r--r-- | Master/Reference Architectures and Patterns/hjp5/examples/Listing3408.java | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing3408.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3408.java new file mode 100644 index 0000000..42c8f4f --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3408.java @@ -0,0 +1,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);
+ }
+ }
+}
\ No newline at end of file |
