如何在网页中实现动画?
animating an array of images in an applet this is the simplest applet to animate an array of images.
import java.applet.*;
import java.awt.*;
public class animapplet extends
applet implements runnable {
image[] images = new image[2];
int frame = 0;
thread thread;
public void init() {
images[0] = getimage(getdocumentbase(),
"http://hostname/image0.gif");
images[1] = getimage(getdocumentbase(),
"http://hostname/image1.gif");
}
public void start() {
(thread = new thread(this)).start();
}
public void stop() {
thread = null;
}
public void paint(graphics g) {
g.drawimage(images[frame], 0, 0, this);
}
public void run() {
int delay = 1000; // 1 second
try {
while (thread == thread.currentthread()) {
frame = (frame+1)%images.length;
repaint();
thread.sleep(delay);
}
} catch (exception e) {
}
}
}
结束!
闽公网安备 35060202000074号