01: import java.awt.event.ActionEvent;
02: import java.awt.event.ActionListener;
03: import javax.swing.JOptionPane;
04: import javax.swing.Timer;
05: 
06: /**
07:    This program tests the Timer class.
08: */
09: public class TimerTester
10: {
11:    public static void main(String[] args)
12:    {
13:       class CountDown implements ActionListener
14:       {
15:          public CountDown(int initialCount)
16:          {
17:             count = initialCount;
18:          }
19: 
20:          public void actionPerformed(ActionEvent event)
21:          {
22:             if (count >= 0)
23:                System.out.println(count);
24:             if (count == 0)
25:                System.out.println("Liftoff!");
26:             count--;
27:          }
28: 
29:          private int count;
30:       }
31: 
32:       CountDown listener = new CountDown(10);
33: 
34:       final int DELAY = 1000; // Milliseconds between timer ticks
35:       Timer t = new Timer(DELAY, listener);
36:       t.start();
37: 
38:       JOptionPane.showMessageDialog(null, "Quit?");
39:       System.exit(0);
40:    }
41: }