会员: 密码:  免费注册 | 忘记密码 | 会员登录 网页功能: 加入收藏 设为首页 网站搜索  
技术文档 > JAVA
动画小程序实现的基本步骤
发表日期:2004-07-27 17:50:24作者: 出处:  


如何在网页中实现动画?

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

返回顶部】 【打印本页】 【关闭窗口

关于我们 / 给我留言 / 版权举报 / 意见建议 / 网站编程QQ群   
Copyright ©2003- 2024 Lihuasoft.net webmaster(at)lihuasoft.net 加载时间 0.00396