package com.example.demo.Test; 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 TimerTest { public static void main(String[] args) { ActionListener actionListener = new TimerPrinter(); //间隔5s通知listen一次 Timer t = new Timer(5000,actionListener); t.start(); //显示一个包含一条消息和ok按钮的对话框,这个对话框位于parent组件的中央,parent为null则显示在屏幕中央 JOptionPane.showMessageDialog(null,"中央弹框"); System.exit(0); } static class TimerPrinter implements ActionListener{ public void actionPerformed(ActionEvent e) { System.out.println("at the once ,the time is:"+ new Date()); //获取默认工具箱 ,工具箱包含GUI环境信息 //void beep();发出一声铃响 Toolkit.getDefaultToolkit().beep(); } } }
07-27
07-21
503