定时器

package interfaceDemo;

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;

/**
* 
* @author qz:
* @version 创建时间:2019年10月18日 下午5:16:36
* 
*/
public class TimerTest {

    public static void main(String[] args) {
        // TODO Auto-generated method stub

        ActionListener listener = new TimePrinter();
        
        Timer t = new Timer(10000,listener);
        t.start();
        
        JOptionPane.showMessageDialog(null, "Quit program?");
        System.exit(0);
        
    }

}


class TimePrinter implements ActionListener{

    @Override
    public void actionPerformed(ActionEvent e) {
        // TODO Auto-generated method stub
        System.out.println("At the tone,the time is "+new Date());
        Toolkit.getDefaultToolkit().beep();
    }
    
}

你可能感兴趣的:(定时器)