corejava第10版
This commit is contained in:
1 parent
2021c3c227
commit
6165543dd3
1088 files changed
+94411
No files matched your search
@@ -0,0 +1,38 @@
|
||||
package timer;
|
||||
|
||||
/**
|
||||
@version 1.01 2015-05-12
|
||||
@author Cay Horstmann
|
||||
*/
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.util.*;
|
||||
import javax.swing.*;
|
||||
import javax.swing.Timer;
|
||||
// to resolve conflict with java.util.Timer
|
||||
|
||||
public class TimerTest
|
||||
{
|
||||
public static void main(String[] args)
|
||||
{
|
||||
ActionListener listener = new TimePrinter();
|
||||
|
||||
// construct a timer that calls the listener
|
||||
// once every 10 seconds
|
||||
Timer t = new Timer(10000, listener);
|
||||
t.start();
|
||||
|
||||
JOptionPane.showMessageDialog(null, "Quit program?");
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
class TimePrinter implements ActionListener
|
||||
{
|
||||
public void actionPerformed(ActionEvent event)
|
||||
{
|
||||
System.out.println("At the tone, the time is " + new Date());
|
||||
Toolkit.getDefaultToolkit().beep();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user