Java Reference
In-Depth Information
Low-Level Events: These are system-level events that arise from the keyboard or from the mouse,
or events associated with operations on a window, such as reducing it to an icon or closing it. The
meaning of a low-level event is something like “the mouse was moved," “this window has been
closed," or “this key was pressed."
Semantic Events: These are specific GUI component-level events such as selecting a button by
clicking it to cause some program action or adjusting a scrollbar. They originate, and you interpret
them, in the context of the GUI you have created for your program. The meaning of a semantic
event is typically along the lines of “the OK button was pressed," or “the Save menu item was se-
lected." Each kind of component, a button or a menu item, for example, can generate a particular
kind of semantic event.
These two categories can seem to be a bit confusing as they overlap in a way. If you click a button, you
create a semantic event as well as a low-level event. The click produces a low-level event object in the form
of “the mouse was clicked" as well as a semantic event “the button was pushed." In fact it produces more
than one mouse event, as you later see. Whether your program handles the low-level events or the semantic
events, or possibly both kinds of events, depends on what you want to do.
Most of the events relating to the GUI for a program are represented by classes that are in the
java.awt.event package. This package also defines the listener interfaces for various kinds of events. The
package javax.swing.event defines classes for events that are specific to Swing components.
Low-Level Event Classes
You can elect to handle four kinds of low-level events in your programs. They are represented by the classes
in the java.awt.event package that are shown in Table 18-1 .
TABLE 18-1 : Classes for Low-Level Events
EVENT DESCRIPTION
FocusEvent Objects of this class represent events that originate when a component gains or loses the focus. Only the
component that has the focus can receive input, so it is usually highlighted or has the cursor displayed.
MouseEvent These are events that result from user actions with the mouse, such as moving the mouse or pressing a
mouse button. You learn how you deal with these events in Chapter 19.
KeyEvent These represent events that arise from pressing keys on the keyboard.
WindowEvent Objects of this class represent events that relate to a window, such as activating or deactivating it, redu-
cing it to its icon, or closing it. These events relate to objects of type Window or any subclass of Window .
The MouseEvent class has two subclasses that identify more specialized mouse events. One is the
MenuDragMouseEvent class that defines events that signal when the mouse is dragged over a menu item.
The other is the MouseWheelEvent class that defines events indicating when the mouse wheel is rotated.
WARNING Just so that you know, this isn ' t an exhaustive list of all of the low-level event
classes. It ' s a list of the ones you need to know about. For example, there ' s also the
PaintEvent class that is concerned with the internals of how components are painted on the
screen.There ' salsoanotherlow-leveleventclass, ContainerEvent ,thatdefineseventsrelat-
ing to a container, such as adding or removing components. You can ignore these classes, as
these events are handled automatically.
 
 
Search WWH ::




Custom Search