e558. 在Applet中多图片交互显示

Posted borter

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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

以上是关于e558. 在Applet中多图片交互显示的主要内容,如果未能解决你的问题,请参考以下文章

在java Applet里如何实现鼠标滚轮放大缩小图片?

CF-558E (线段树/分块)

java怎么显示本地图片

错误记录Flutter 混合开发获取 BinaryMessenger 报错 ( FlutterActivityAndFragmentDelegate.getFlutterEngine() )(代码片段

为啥制作的form表单会在网页显示中多出一行

CardView 不在披萨片段中显示图片