O'Reilly logo

Graphic Java™ 1.2, Volume I: AWT, Third Edition by David M. Geary

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Firing AWT Events from Custom Components

A good percentage of AWT components fire some sort of semantic event. Likewise, many custom components perform one or more actions that could be construed as semantic events. Equipping a custom component to fire semantic events is a fairly common and, thankfully, straightforward task that can be enumerated as follows:

  1. Have the component implement a listener interface, if appropriate.

  2. Add an appropriate listener member to the class.

  3. Implement addXXXListener() and removeXXXListener().

  4. Implement processXXXEvent().

Example 9-25 lists the ThreeDButton class modified to fire action events under the same circumstances that java.awt.Button does.

Example 9-25. ThreeDButton That Fires Action Events
 import java.applet.Applet; ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required