- import java.awt.*;
- import java.awt.event.*;
- import java.util.*;
- import javax.swing.*;
- import javax.swing.Timer;
- public class TimerTest
- {
- public static void main(String[] args)
- {
- ActionListener p = new TimerPrinter();
- Timer t = new Timer(1000,p);
- t.start();
- JOptionPane.showMessageDialog(null,"Quit Program?");
- System.exit(0);
- }
- }
- class TimerPrinter implements ActionListener
- {
- public void actionPerformed(ActionEvent e)
- {
- Date now = new Date();
- System.out.println("Print time:" + now);
- Toolkit.getDefaultToolkit().beep();
- }
- }
Timer--ActionListener接口
最新推荐文章于 2024-09-22 17:08:16 发布