Java Reference
In-Depth Information
Go ahead and run the RectangleComponentViewer program. Whenever you
click the mouse inside the frame, the top left corner of the rectangle moves to the
mouse pointer (see Figure 5 ).
423
424
Figure 5
Clicking the Mouse Moves the Rectangle
ch09/mouse/RectangleComponentViewer.java
1 import java.awt.event.MouseListener;
2 import java.awt.event.MouseEvent;
3 import javax.swing.JFrame;
4
5 /**
6 This program displays a RectangleComponent.
7 */
8 public class RectangleComponentViewer
9 {
10 public static void main(String[] args)
11 {
12 final RectangleComponent component = new
RectangleComponent();
13
Search WWH ::




Custom Search