Java Reference
In-Depth Information
K
GUI Events
Throughout the Graphics Track sections of this topic, we've discussed various
events that components might generate. The goal of this appendix is to put the
event/component relationship into context.
The events listed in Figure K.1 are generated by every Swing component. That
is, we can set up a listener for any of these events on any component.
Some events are generated only by certain components. The table in Figure K.2
maps the components to the events that they can generate. Keep in mind that these
events are in addition to the ones that all components generate. If a component
does not generate a particular kind of event, a listener for that event cannot be
added to that component.
We have discussed some of the events in Figures K.1 and K.2 at appropriate
points in this text; we have left others for your independent exploration. Applying
the basic concept of component/event/listener interaction is often just a matter of
knowing which components generate which events under which circumstances.
Of course, many events occur in a GUI that have no bearing on the current
program. For example, every time a mouse is moved across a component, many
mouse motion events are generated. However, this doesn't mean we must listen
for them. A GUI is defined in part by the events to which we choose to respond.
Despite our heavy coverage of GUI development in this topic, we've still only
scratched the surface. The following list describes a few other Java GUI containers
and components that are not covered in depth in this text:
Event
Represents
Component Event
Changing a component's size, position, or visibility.
Focus Event
Gaining or losing the keyboard focus.
Key Event
Pressing, releasing, and clicking keyboard keys.
Mouse Event
Clicking the mouse button and moving the mouse into and out of
a component's drawing area.
Mouse Motion Event
Moving or dragging a mouse over a component.
FIGURE K.1 Events that are generated by every Swing component
715
 
Search WWH ::




Custom Search