01: import java.awt.Rectangle;
02: import java.awt.event.ActionEvent;
03: import java.awt.event.ActionListener;
04: import javax.swing.JOptionPane;
05: import javax.swing.Timer;
06: 
07: /**
08:    This program uses a timer to move a rectangle once per second.
09: */
10: public class TimerTester2
11: {
12:    public static void main(String[] args)
13:    {
14:       final Rectangle box = new Rectangle(5, 10, 20, 30);
15: 
16:       class Mover implements ActionListener
17:       {
18:          public void actionPerformed(ActionEvent event)
19:          {
20:             box.translate(1, 1);
21:             System.out.println(box);
22:          }
23:       }
24: 
25:       ActionListener listener = new Mover();
26: 
27:       final int DELAY = 100; // Milliseconds between timer ticks
28:       Timer t = new Timer(DELAY, listener);
29:       t.start();
30: 
31:       JOptionPane.showMessageDialog(null, "Quit?");
32:       System.out.println("Last box position: " + box);
33:       System.exit(0);
34:    }
35: }