⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 animatortemplate.java

📁 java applet编程,实现对相关图片声音的调用
💻 JAVA
字号:
import java.awt.*;import java.applet.Applet;/*  * Based on Arthur van Hoff's animation examples, this applet * can serve as a template for all animation applets. */public class AnimatorTemplate extends Applet                            implements Runnable {    int frameNumber = -1;    int delay;    Thread animatorThread;    boolean frozen = false;    public void init() {        String str;        int fps = 10;        //How many milliseconds between frames?        str = getParameter("fps");        try {            if (str != null) {                fps = Integer.parseInt(str);            }        } catch (Exception e) {}        delay = (fps > 0) ? (1000 / fps) : 100;    }    public void start() {        if (frozen) {             //Do nothing.  The user has requested that we             //stop changing the image.        } else {            //Start animating!            if (animatorThread == null) {                animatorThread = new Thread(this);            }            animatorThread.start();        }    }    public void stop() {        //Stop the animating thread.        animatorThread = null;    }    public void run() {        //Just to be nice, lower this thread's priority        //so it can't interfere with other processing going on.        Thread.currentThread().setPriority(Thread.MIN_PRIORITY);        //Remember the starting time.        long startTime = System.currentTimeMillis();        //Remember which thread we are.        Thread currentThread = Thread.currentThread();        //This is the animation loop.        while (currentThread == animatorThread) {            //Advance the animation frame.            frameNumber++;            //Display it.            repaint();            //Delay depending on how far we are behind.            try {                startTime += delay;                Thread.sleep(Math.max(0,                              startTime-System.currentTimeMillis()));            } catch (InterruptedException e) {                break;            }        }    }    //Draw the current frame of animation.    public void paint(Graphics g) {        g.drawString("Frame " + frameNumber, 0, 30);    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -