-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTimerTest.java
More file actions
35 lines (28 loc) · 836 Bytes
/
TimerTest.java
File metadata and controls
35 lines (28 loc) · 836 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package timer;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Date;
/**
* @author Cay Horstmann
* @version 1.01 2015-05-12
*/
public class TimerTest {
public static void main(String[] args) {
ActionListener listener = new TimerPrinter();
// construct a timer that calls the listen
// once every 10 second
Timer timer = new Timer(10000, listener);
timer.start();
JOptionPane.showMessageDialog(null, "Quit program?");
System.exit(0);
}
}
class TimerPrinter implements ActionListener {
@Override
public void actionPerformed(ActionEvent actionEvent) {
System.out.println("At the tone, the time is " + new Date());
Toolkit.getDefaultToolkit().beep();
}
}