package interfacepage; import java.awt.Toolkit; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.Timer; public class TimerTest implements ActionListener { /** * 回调 * * ActionListener 监听,回调actionPerformed方法 * * Timer 定时 * */ public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub System.out.println("listener"); Toolkit.getDefaultToolkit().beep(); } /** * @author:lixh */ public static void main(String[] args) { // TODO Auto-generated method stub ActionListener listener = new TimerTest(); Timer t = new Timer(1000, listener); t.start(); } }