【e581. Animating an Array of Images in an Application】男儿欲遂平生志,六经勤向窗前读。这篇文章主要讲述e581. Animating an Array of Images in an Application相关的知识,希望能为你提供帮助。
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 secondtry { 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 |
推荐阅读
- ABP中mapping中忽略属性
- e557. 在Applet中显示图片
- Unity输出PC端(Windows) 拖拽文件到app中
- e558. 在Applet中多图片交互显示
- e552. 取Applet的参数
- SVG g元素用法详解
- SVG教程入门介绍
- SVG第一个例子详解
- Struts 2项目(登录和注销示例)