1  import java.awt.event.ActionEvent;
  2  import java.awt.event.ActionListener;
  3  import javax.swing.JFrame;
  4  import javax.swing.Timer;
  5  
  6  /** 	 	 	 	 	 	
  7     This frame contains a moving rectangle.
  8  */
  9  public class RectangleFrame extends JFrame
 10  {
 11     private static final int FRAME_WIDTH = 300;
 12     private static final int FRAME_HEIGHT = 400;
 13  
 14     private RectangleComponent scene;
 15  
 16     class TimerListener implements ActionListener
 17     {
 18        public void actionPerformed(ActionEvent event)
 19        {
 20           scene.moveRectangleBy(1, 1);
 21        }
 22     }
 23  
 24     public RectangleFrame()
 25     {
 26        scene = new RectangleComponent();
 27        add(scene);
 28  
 29        setSize(FRAME_WIDTH, FRAME_HEIGHT);
 30        
 31        ActionListener listener = new TimerListener();
 32  
 33        final int DELAY = 100; // Milliseconds between timer ticks
 34        Timer t = new Timer(DELAY, listener);
 35        t.start();      
 36     }
 37  }