标签:
public AlarmLock{
private int delay;
private int flag;
public AlarmLock(int delay,int flag){
this.delay = delay;
this.flag = flag ;
}
提供一个方法供外部使用
public void start(){
//创建一个方内部类
class Printer implements ActionListener(ActionEvent e){
//将时间转化为格式化字符串
DateFormate format = new SimpleDateFormate("hh:mm:ss");
String result = format.format(new Date());
System.out.println("当前时间:"+result);
if(flag){
Tookit.getDefaultToolkit().beep();
}
}
}
new Timer(delay,new Printer()).start();
}
public class Test{
public static void main(String[] args){
AlarmClork clork = new AlarmClock(100,true);
clock.start();
JOptionPane.showMessageDialog(null ,"是否退出");
System.exit(0);
}
}
标签:
原文地址:http://www.cnblogs.com/chengbao/p/4822899.html