From 33613a85afc4b1481367fbe92a17ee59c240250b Mon Sep 17 00:00:00 2001 From: Sven Eisenhauer Date: Fri, 10 Nov 2023 15:11:48 +0100 Subject: add new repo --- .../hjp5/examples/Listing3408.java | 73 ++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 Master/Reference Architectures and Patterns/hjp5/examples/Listing3408.java (limited to 'Master/Reference Architectures and Patterns/hjp5/examples/Listing3408.java') 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 -- cgit v1.2.3