01: import java.awt.*;
02: import java.awt.event.*;
03: import javax.swing.*;
04: 
05: /**
06:    This program implements an animation that moves
07:    a car shape.
08: */
09: public class AnimationTester
10: {
11:    public static void main(String[] args)
12:    {
13:       JFrame frame = new JFrame();
14: 
15:       final MoveableShape shape
16:             = new CarShape(0, 0, CAR_WIDTH);
17: 
18:       ShapeIcon icon = new ShapeIcon(shape,
19:             ICON_WIDTH, ICON_HEIGHT);
20: 
21:       final JLabel label = new JLabel(icon);
22:       frame.setLayout(new FlowLayout());
23:       frame.add(label);
24: 
25:       frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
26:       frame.pack();
27:       frame.setVisible(true);
28: 
29:       final int DELAY = 100;
30:       // Milliseconds between timer ticks
31:       Timer t = new Timer(DELAY, new
32:          ActionListener()
33:          {
34:             public void actionPerformed(ActionEvent event)
35:             {
36:                shape.translate(1, 0);
37:                label.repaint();
38:             }
39:          });
40:       t.start();
41:    }
42: 
43:    private static final int ICON_WIDTH = 400;
44:    private static final int ICON_HEIGHT = 100;
45:    private static final int CAR_WIDTH = 100;
46: }