zoukankan      html  css  js  c++  java
  • e558. 在Applet中多图片交互显示

    This is the simplest applet to animate an array of images. In practice, you should use double-buffering (which this example does not use) to eliminate flickering.

        import java.applet.*;
        import java.awt.*;
        
        public class AnimApplet extends Applet implements Runnable {
            Image[] images = new Image[2];
            int frame = 0;
            volatile 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) {
                }
            }
        }
    
    Related Examples
  • 相关阅读:
    微信运营
    1.数据库&SQL语言
    16.线程
    15.IO流
    14.异常
    13.集合
    12.常用类
    11.String类-StringBuffer类、StringBuilder类
    10.Object类-包装类-内部类
    9.接口
  • 原文地址:https://www.cnblogs.com/borter/p/9575304.html
Copyright © 2011-2022 走看看