Java code lib javax.swing,Timer定时任务
/** * Created by LvJianwei on 2018/1/24. */ import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.Date; import javax.swing.*; /** * @program: reflection * @description: Timer * @author: LvJianwei * @create: 2018-01-24 10:32 **/ public class TimerTest { public static void main(String[] args) { ActionListener listener = new TimePrinter(); Timer timer=new Timer(1000,listener); timer.start(); JOptionPane.showMessageDialog(null,"Quit program?"); System.exit(0); } } class TimePrinter implements ActionListener{ @Override public void actionPerformed(ActionEvent e) { System.out.println("At the tone,the time is "+new Date()); Toolkit.getDefaultToolkit().beep(); } }
posted on 2018-01-24 11:04 Lv Jianwei 阅读(136) 评论(0) 编辑 收藏 举报