import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Date;
import javax.swing.JOptionPane;
import javax.swing.Timer;
public class Test implements ActionListener{
public void actionPerformed (ActionEvent event){
Date now=new Date();
System.out.println("at the tone,the time is"+now);
//Toolkit.getDefaultToolkit().beep();
System.out.println("OK");
}
public static void main(String[] args){
Test tp=new Test();
Timer timer=new Timer(1000,tp);
timer.start();
JOptionPane.showMessageDialog(null,"quit");
System.exit(0);
}
}
运行结果:
C:\>java Test
at the tone,the time isSun Oct 29 13:40:25 CST 2006
OK
at the tone,the time isSun Oct 29 13:40:25 CST 2006
OK
at the tone,the time isSun Oct 29 13:40:26 CST 2006
OK
at the tone,the time isSun Oct 29 13:40:27 CST 2006
OK
at the tone,the time isSun Oct 29 13:40:28 CST 2006
OK
at the tone,the time isSun Oct 29 13:40:29 CST 2006
OK
at the tone,the time isSun Oct 29 13:40:30 CST 2006
OK
at the tone,the time isSun Oct 29 13:40:31 CST 2006
OK
at the tone,the time isSun Oct 29 13:40:32 CST 2006
OK