Java provides a number of classes and interfaces for working with events. They fall into four general categories:
- events, per se
- registration
- forwarding
- receiving
You should look closely at the positions of the relevant classes within the overall Java class hierarchy and at the methods that are available in each. Pay particular attention to inherited methods.
In this discussion, only the classes associated with
Events
, per se, will be considered. Subsequent sections will consider classes associated with registration, forwarding, and receiving.The superclass of all events is
EventObject
, derived fromObject
, and included in thejava.util
package.
EventObject
has two primary subclasses. One of them,AWTEvent
, is the superclass for the different kinds of events that occur with respect to various user interface components. It is this group of events that will be considered in the two Events lessons, here. The other subclass is concerned with events that occur with respect to Java beans, and will not be considered.For convenience,
AWTEvent
and its kin have been grouped into a separate package, calledjava.awt.event
. It includes some dozen different kinds of events, each of which includes variables and methods relevant to a particular type of ui component. For example,ActionEvent
is the event type generated by buttons, lists, menu items, and textfields. Similarly, aMouseEvent
is generated whenever the user moves the mouse, presses a mouse button, releases it, etc. As would be expected, it includes methods that return data such as the x,y coordinates of the mouse when it was clicked or moved.The class hierarchy for AWTEvents is as follows:
Object (java.lang) EventObject (java.util) AWTEvent (java.awt) ActionEvent (java.awt.event) AdjustmentEvent ComponentEvent ContainerEvent FocusEvent InputEvent KeyEvent MouseEvent PaintEvent WindowEvent ItemEvent TextEvent