Java Reference
In-Depth Information
Figure 7.1 The interactive application. Only 14 circles are shown, rather than the 15 given
on the status panel, as 2 occupy the same location
7.5
Running the application
Our interactive application is now complete. The result is shown in Figure 7.1.
Note that more than one circle can be at the same coordinates in which case one
'sees' fewer circles than there actually are. The number of circles displayed in the
status panel is always correct. Some circles might also be invisible because the
frame was resized and they are now outside the visible area.
7.6
Summary and remarks
7.6.1
Mouse listeners
We have seen how the two mouse listeners work. A MouseListener becomes active
when the mouse buttons are used or the mouse leaves or enters the component to
which the listener is assigned. A MouseMotionListener becomes active whenever
the mouse is moved. The mouse event object generated by the runtime system
contains information on the type of event and the location where it occurred.
The following steps are necessary to implement mouse listeners:
1. Determine inside which component the mouse should be tracked.
2. Create a mouse (motion) listener. That is, define in method mouseClicked ,
etc. what has to happen in response to an event.
3. Assign the action listener to the relevant component.
Search WWH ::




Custom Search