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 TimerTester3
11: {
12:    public static void main(String[] args)
13:    {
14:       final Rectangle box = new Rectangle(5, 10, 20, 30);
15:       final int DELAY = 100; // Milliseconds between timer ticks
16:
17:	  Timer t = new Timer(DELAY, new ActionListener() {
18:		public void actionPerformed(ActionEvent evt) {
19:             	box.translate(1, 1);
20:             	System.out.println(box);
21:          	}
22:	   }); 
23:       t.start();
24: 
25:       JOptionPane.showMessageDialog(null, "Quit?");
26:       System.out.println("Last box position: " + box);
27:       System.exit(0);
28:    }
29: }