1  import java.awt.event.MouseListener;
  2  import java.awt.event.MouseEvent;
  3  import javax.swing.JFrame;
  4  
  5  /** 	 	 	 	 	 	
  6     This frame contains a moving rectangle.
  7  */
  8  public class RectangleFrame2 extends JFrame
  9  {
 10     private static final int FRAME_WIDTH = 300;
 11     private static final int FRAME_HEIGHT = 400;
 12  
 13     private RectangleComponent2 scene;
 14  
 15     class MousePressListener implements MouseListener
 16     {  
 17        public void mousePressed(MouseEvent event)
 18        {  
 19           int x = event.getX();
 20           int y = event.getY();
 21           scene.moveRectangleTo(x, y);
 22        }
 23  
 24        // Do-nothing methods
 25        public void mouseReleased(MouseEvent event) {}
 26        public void mouseClicked(MouseEvent event) {}
 27        public void mouseEntered(MouseEvent event) {}
 28        public void mouseExited(MouseEvent event) {}
 29     }
 30           
 31     public RectangleFrame2()
 32     {
 33        scene = new RectangleComponent2();
 34        add(scene);
 35  
 36        MouseListener listener = new MousePressListener();
 37        scene.addMouseListener(listener);
 38  
 39        setSize(FRAME_WIDTH, FRAME_HEIGHT);
 40     }
 41  }