You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
70 lines
1.9 KiB
70 lines
1.9 KiB
15 years ago
|
package net.yacy.visualization;
|
||
18 years ago
|
|
||
|
import java.applet.Applet;
|
||
|
import java.awt.Dimension;
|
||
|
import java.awt.Graphics;
|
||
|
|
||
|
|
||
15 years ago
|
|
||
|
public class DemoApplet extends Applet implements Runnable {
|
||
18 years ago
|
// can be run in eclipse with
|
||
|
// Run -> Run As -> Java Applet
|
||
|
|
||
|
// see http://www.javaworld.com/javaworld/jw-03-1996/jw-03-animation.html?page=3
|
||
|
|
||
|
private static final long serialVersionUID = -8230253094143014406L;
|
||
|
|
||
|
int delay;
|
||
|
Thread animator;
|
||
|
Dimension offDimension;
|
||
15 years ago
|
RasterPlotter offGraphics;
|
||
18 years ago
|
|
||
|
public void init() {
|
||
17 years ago
|
final String str = getParameter("fps");
|
||
|
final int fps = (str != null) ? Integer.parseInt(str) : 10;
|
||
18 years ago
|
delay = (fps > 0) ? (1000 / fps) : 100;
|
||
|
}
|
||
|
|
||
|
public void start() {
|
||
|
animator = new Thread(this);
|
||
|
animator.start();
|
||
|
}
|
||
|
|
||
|
public void run() {
|
||
|
while (Thread.currentThread() == animator) {
|
||
17 years ago
|
final long time = System.currentTimeMillis();
|
||
18 years ago
|
repaint();
|
||
|
try {
|
||
|
Thread.sleep(delay - System.currentTimeMillis() + time);
|
||
17 years ago
|
} catch (final InterruptedException e) {
|
||
18 years ago
|
break;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public void stop() {
|
||
|
animator = null;
|
||
|
}
|
||
|
|
||
17 years ago
|
public void update(final Graphics g) {
|
||
|
final Dimension d = getSize();
|
||
15 years ago
|
offGraphics = new RasterPlotter(d.width, d.height, RasterPlotter.MODE_REPLACE, "FFFFFF");
|
||
18 years ago
|
paintFrame(offGraphics);
|
||
|
g.drawImage(offGraphics.getImage(), 0, 0, null);
|
||
|
}
|
||
|
|
||
17 years ago
|
public void paint(final Graphics g) {
|
||
18 years ago
|
if (offGraphics != null) {
|
||
|
g.drawImage(offGraphics.getImage(), 0, 0, null);
|
||
|
}
|
||
|
}
|
||
|
|
||
15 years ago
|
public void paintFrame(final RasterPlotter m) {
|
||
|
RasterPlotter.demoPaint(m);
|
||
17 years ago
|
final int y = (int) (System.currentTimeMillis() / 10 % 300);
|
||
15 years ago
|
m.setColor(RasterPlotter.GREY);
|
||
|
PrintTool.print(m, 0, y, 0, "Hello World", -1);
|
||
18 years ago
|
}
|
||
|
|
||
|
}
|