Java Reference
In-Depth Information
6.4
A first mouse application
6.4.1
Specification of the application
Let us specify the application that demonstrates the mouse listeners. The compo-
nent to which the mouse listeners are associated will be a 300
300 panel that is
centrally placed in a frame. Below that is another panel which displays information
about the mouse. We would like to display the current mouse position, the number
of clicks of the mouse button and whether the mouse is inside or outside the 300
×
×
300 panel. The information is continuously updated. The intended layout can be
seen in Figure 6.1. We describe the implementation of the view and control parts;
a model part is not implemented because there is hardly any data to be handled.
6.4.2
The view part
For the implementation we define the class MouseEventPanel . The panel (now)
has no methods of its own; it serves only as a playground for the mouse. It will be
the central component in a frame of type MouseEventFrame which we also define.
The mouse listeners will be assigned to this panel. They will then track the mouse
while it is in the panel.
Below the mouse event panel (South) we add another panel to the frame. This
is of type StatusPanel and will be used to display information on the mouse.
position:
x = 137
27
y = 53
number of clicks:
mouse is in component: yes
Figure 6.1 The layout of the first mouse application
Search WWH ::




Custom Search