01: package de.anomic.ymage;
02:
03: import java.applet.Applet;
04: import java.awt.Dimension;
05: import java.awt.Graphics;
06:
07: public class ymageDemoApplet extends Applet implements Runnable {
08: // can be run in eclipse with
09: // Run -> Run As -> Java Applet
10:
11: // see http://www.javaworld.com/javaworld/jw-03-1996/jw-03-animation.html?page=3
12:
13: private static final long serialVersionUID = -8230253094143014406L;
14:
15: int delay;
16: Thread animator;
17: Dimension offDimension;
18: ymageMatrix offGraphics;
19:
20: public void init() {
21: String str = getParameter("fps");
22: int fps = (str != null) ? Integer.parseInt(str) : 10;
23: delay = (fps > 0) ? (1000 / fps) : 100;
24: }
25:
26: public void start() {
27: animator = new Thread(this );
28: animator.start();
29: }
30:
31: public void run() {
32: while (Thread.currentThread() == animator) {
33: long time = System.currentTimeMillis();
34: repaint();
35: try {
36: Thread.sleep(delay - System.currentTimeMillis() + time);
37: } catch (InterruptedException e) {
38: break;
39: }
40: }
41: }
42:
43: public void stop() {
44: animator = null;
45: }
46:
47: public void update(Graphics g) {
48: Dimension d = getSize();
49: offGraphics = new ymageMatrix(d.width, d.height,
50: ymageMatrix.MODE_REPLACE, "FFFFFF");
51: paintFrame(offGraphics);
52: g.drawImage(offGraphics.getImage(), 0, 0, null);
53: }
54:
55: public void paint(Graphics g) {
56: if (offGraphics != null) {
57: g.drawImage(offGraphics.getImage(), 0, 0, null);
58: }
59: }
60:
61: public void paintFrame(ymageMatrix m) {
62: ymageMatrix.demoPaint(m);
63: int y = (int) (System.currentTimeMillis() / 10 % 300);
64: m.setColor(ymageMatrix.GREY);
65: ymageToolPrint.print(m, 0, y, 0, "Hello World", -1);
66: }
67:
68: }
|