reminderbeep.java

来自「初期JAVA学习非常有用的资料。帮助深入了解API。特别是Applet。」· Java 代码 · 共 35 行

JAVA
35
字号
import java.util.Timer;import java.util.TimerTask;import java.awt.Toolkit;/** * Simple demo that uses java.util.Timer to schedule a task to execute * once 5 seconds have passed. */public class ReminderBeep {    Toolkit toolkit;    Timer timer;    public ReminderBeep(int seconds) {	toolkit = Toolkit.getDefaultToolkit();        timer = new Timer();        timer.schedule(new RemindTask(), seconds*1000);    }    class RemindTask extends TimerTask {        public void run() {            System.out.println("Time's up!");	    toolkit.beep();	    //timer.cancel(); //Not necessary because we call System.exit	    System.exit(0);   //Stops the AWT thread (and everything else)        }    }    public static void main(String args[]) {	System.out.println("About to schedule task.");        new ReminderBeep(5);	System.out.println("Task scheduled.");    }}

⌨️ 快捷键说明

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