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

📄 basicanimate.java

📁 Sensor net work simulator in Java
💻 JAVA
字号:
import java.awt.*;import java.awt.event.*;import java.applet.*;public class BasicAnimate extends Applet implements Runnable {    /**     * The thread that is used to drive the animation.     */    private Thread thread = null;    /**     * The off-screen image used for double buffering.     */    private Image offscreenImage = null;    /**     * The off-screen graphics context, used to draw to     * the off-screen image.     */    private Graphics offscreenGraphics = null;    /**     * The primary graphics context, drawing to this     * context will draw directly to the applet.     */    private Graphics primaryGraphics = null;    /**     * If done is set to true, then the applet will     * stop.     */    private boolean done;    /**     * Increases one for each "pulse", or frame of animation.     */    private long pulseCount;    /**     * How many miliseconds should each pulse last.     */    private int pulseLength = 100;    /**     * Use this constant to specify big-endian integers.     */    private boolean doubleBuffer = true;    /**     * This method sets up for applet or Frame usage. For an     * applet, it will be called automatically. For a frame, you     * should call this method as part of your setup.     *     * @param f The file to read/write from/to.     */    @Override    public void init() {        thread = new Thread(this);        offscreenImage = createImage(getWidth(), getHeight());        offscreenGraphics = offscreenImage.getGraphics();        primaryGraphics = getGraphics();        pulseCount = 0;        thread.start();    }    /**     * This method is called to paint the off-screen image.     * It is called for each frame of animation. You should     * override this method in derived classes. To find out     * what "frame" the animation is on access the pulseCount     * property.     *     * @param g The off-screen graphics object to paint to.     */    public void paintOffscreen(Graphics g) {        // paint the off-screen image        g.setColor(Color.white);        g.fillRect(0, 0, getWidth(), getHeight());    }    /**     * Used internally to drive the animation. You should not     * generally need to override this method.     *     * @param f The file to read/write from/to.     */    public void run() {        done = false;        while (!done) {            try {                // pause for this frame                Thread.sleep(pulseLength);                // draw the off-screen image                if (doubleBuffer) {                    paintOffscreen(offscreenGraphics);                } else {                    paintOffscreen(primaryGraphics);                }                // paint off-screen image to primary display, if needed                if (doubleBuffer) {                    primaryGraphics.drawImage(offscreenImage, 0, 0, this);                }                // increase the pulse count                pulseCount++;            } catch (InterruptedException e) {            }        }    }    public void setPulseLength(int pulseLength) {        this.pulseLength = pulseLength;    }    public int getPulseLength() {        return pulseLength;    }    public void setDoubleBuffer(boolean doubleBuffer) {        this.doubleBuffer = doubleBuffer;    }    public boolean getDoubleBuffer() {        return doubleBuffer;    }    public void setPulseCount(long pulseCount) {        this.pulseCount = pulseCount;    }    public long getPulseCount() {        return pulseCount;    }}

⌨️ 快捷键说明

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