This is the simplest application to animate an array of images.

    import java.awt.*;
import javax.swing.*; public class AnimApp extends JComponent implements Runnable {
Image[] images = new Image[2];
int frame = 0; public void paint(Graphics g) {
Image image = images[frame];
if (image != null) {
// Draw the current image
int x = 0;
int y = 0;
g.drawImage(image, x, y, this);
}
} public void run() {
// Load the array of images
images[0] = new ImageIcon("image1.gif").getImage();
images[1] = new ImageIcon("image2.gif").getImage(); // Display each image for 1 second
int delay = 1000; // 1 second try {
while (true) {
// Move to the next image
frame = (frame+1)%images.length; // Causes the paint() method to be called
repaint(); // Wait
Thread.sleep(delay);
}
} catch (Exception e) {
}
} public static void main(String[] args) {
AnimApp app = new AnimApp(); // Display the animation in a frame
JFrame frame = new JFrame();
frame.getContentPane().add(app);
frame.setSize(300, 300);
frame.setVisible(true); (new Thread(app)).start();
}
}
Related Examples

最新文章

  1. Windows下的Eclipse启动出现:a java runtime environment(JRE) or java development kit(JDK) must be
  2. POJ1185炮兵阵地(状态压缩 + dp)
  3. Mobile Web调试工具Weinre (reproduce)
  4. HDU 3333-Turing Tree(BIT好题)
  5. SpringMVC+Spring3+hibernate4 开发环境搭建以及一个开发实例教程
  6. 第1章 网络编程基础(4)——TCP/IP通信
  7. [Usaco2008 Feb]Line连线游戏[暴力][水题]
  8. Linux入门篇(一)——基本命令
  9. C语言野指针
  10. Python进阶之函数式编程
  11. 改变一下主要发博的方向吧...转scratch!
  12. 最新的windows xp sp3序列号 xp序列号
  13. 注解 java.lang.annotation.Inherited 介绍
  14. Python enumerate() 函数
  15. 获取Gitlab项目的Token
  16. C++ 函数模板重载
  17. 转载 Unity Text 插入超链接
  18. Python实现EXCEL表格的排序功能
  19. 页面引入js问题
  20. 【bzoj1568】 JSOI2008—Blue Mary开公司

热门文章

  1. C#--readlyonly关键字
  2. (Apache)ab 压力测试 简单使用
  3. 解决dva dispatch yield生成器函数中异常中断,无法继续调用的问题
  4. mysql 批量更新常用操作
  5. env命令详解
  6. DMA&PIO
  7. AI落地企业业务的一些问题
  8. linux系统资源网站
  9. qt 例子地址
  10. singer页面点击歌手singer是跳转到singer-detail的设置