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

📄 stopwatch.java

📁 鲨鱼攻击猎物游戏 是一个Applet程序
💻 JAVA
字号:
package shark;

import javax.swing.*;

/**
 * 该类用于显示时间的流逝
 */
public class StopWatch extends JLabel implements Runnable {
    private Thread thread = null;

    private int count = 0;

    public StopWatch() {
        super("Time expired:   0 seconds");
    }

    public void start() {
        count = 0;
        thread = new Thread(this);
        thread.start();
    }

    public void stop() {
        thread = null;
    }

    //启动一个线程,每隔一秒钟计数一次
    public void run() {
        Thread currentThread = Thread.currentThread();
        while (thread == currentThread) {
            setText("Expired: " + count + " seconds");
            count++;
            try {
                thread.sleep(1000);
            } catch (InterruptedException ie) {
                System.err.println("Error: " + ie);
            }
        }
    }
}

⌨️ 快捷键说明

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