Events in the AWT Package

The components in the java.awt package use the same event model that I’ve just described. Many of the components in the package send event notifications for things such as mouse clicks, button presses, and window resizings. There are a number of standard classes and interfaces available in java.awt.event for dealing with such events and event notifications. It’s interesting to take a look at some of these more closely to see how they are used and how they behave. This will give you some more insight into how the event model works, and how it is employed by one of the core Java packages.

java.awt.Component is the base class for many components in the AWT package. It provides a great deal of functionality that is shared by all components. As such, there are also a number of events that are fired by all components. These events are grouped into a number of event-listener interfaces, which provide methods that are invoked when their associated events occur. Each of these interfaces extends java.util.EventListener. For each of these event-listener interfaces, there is also an event object class used to encapsulate any specific information related to an instance of the event. These event classes all extend the class java.awt.AWTEvent, which is a subclass of java.util.EventObject.

Let’s take a look at one of the event interfaces supported by the java.awt.Component class. This interface, java.awt.event.MouseListener , is used to provide notifications of events ...

Get Developing Java Beans now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.