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

📄 whirl3.java

📁 由于想一次上传成功 所以将二个教程打包成了一个 这些例子几乎包含了所有java的框架集合
💻 JAVA
字号:
import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;

/*
<APPLET
    CODE = whirl3.class
    WIDTH = 300
    HEIGHT = 300 >
</APPLET>
*/

public class whirl3 extends Applet implements ActionListener, Runnable 
{
    Image whirlImages[] = new Image[4];
    Image nowImage; 
    int whirlIndex = 0;
    Thread whirlThread;
    Button suspendButton, resumeButton;
    boolean animateFlag = true;
    boolean goFlag = true;

    public void init() 
    {
        whirlImages[0] = getImage(getCodeBase(), "whirl1.gif");
        whirlImages[1] = getImage(getCodeBase(), "whirl2.gif");
        whirlImages[2] = getImage(getCodeBase(), "whirl3.gif");
        whirlImages[3] = getImage(getCodeBase(), "whirl4.gif");
        suspendButton = new Button("Suspend");
        add(suspendButton); 
        suspendButton.addActionListener(this);
        resumeButton = new Button("Resume");
        add(resumeButton); 
        resumeButton.addActionListener(this);
    }

    public synchronized void actionPerformed(ActionEvent e){
         if(e.getSource() == suspendButton){
         goFlag = false; 
         }
         if(e.getSource() == resumeButton){
         goFlag = true; 
         notify();
         }
    }

    public void start() {
        whirlThread = new Thread(this);
        whirlThread.start();
    }

    public void stop() {
        animateFlag = false;
    }

    public void run() {
        while(animateFlag){
            nowImage = whirlImages[whirlIndex++];
            if(whirlIndex > 3)whirlIndex = 0;
            repaint();
            try {
                Thread.sleep(200);
                synchronized(this){
                while(!goFlag)
                    wait();
                }
            }
            catch(InterruptedException e) { }
        }
    }

    public void paint (Graphics g) 
    {
        if(nowImage != null) g.drawImage(nowImage, 10, 10, this);
    }

    public void update(Graphics g) 
    {
        g.clipRect(10, 10, 280, 280);
        paint(g);
    }
}

⌨️ 快捷键说明

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