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

发布时间:2024-03-07 09:40:05
如何在网页上实现动画? 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) { } } }结束!
上一篇 比较完善的用JAVA解压ZIP
下一篇 Java 编程技术中汉字问题的分析及解决

文章素材均来源于网络,如有侵权,请联系管理员删除。

标签: Java教程Java基础Java编程技巧面试题Java面试题