Java Reference
In-Depth Information
Semantic Events - these are specific component-related events such as pressing 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 selected'. 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 we shall see. Whether your program handles the low-level events or the
semantic event, or possibly both kinds of event, depends on what you want to do.
Most of the events relating to the GUI for a program are represented by classes defined in the package
java.awt.event . This package also defines the listener interfaces for the various kinds of events that
it defines. The package javax.swing.event defines classes for events that are specific to
Swing components.
Low-level Event Classes
There are four kinds of low-level events that you can elect to handle in your programs. They are
represented by the following classes in the java.awt.event package:
Event
Description
FocusEvent
Objects of this class represent events that originate when a component
gains or loses the keyboard focus. Only the component that has the focus
can receive input from the keyboard, so it will usually be highlighted or
have the cursor displayed.
MouseEvent
Objects of this class represent events that result from user actions with the
mouse such as moving the mouse or pressing a mouse button.
KeyEvent
Objects of this class 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 a window, reducing a window to its icon, or
closing a window. These events relate to objects of the Window class or any
subclass of Window .
The MouseEvent class has two subclasses that identify more specialized mouse events. One is the
MenuDragMouseEvent class that defines event objects signaling when the mouse has been dragged
over a menu item. The other is the MouseWheelEvent class that defines event objects indicating when
the mouse wheel is rotated.
Search WWH ::




Custom Search