服务热线:13616026886

技术文档 欢迎使用技术文档,我们为你提供从新手到专业开发者的所有资源,你也可以通过它日益精进

位置:首页 > 技术文档 > JAVA > 新手入门 > 基础入门 > 查看文档

动画小程序实现的基本步骤


  如何在网页中实现动画?

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) {
}
}
}
结束!

扫描关注微信公众号