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:
Have the component implement a listener interface, if appropriate.
Add an appropriate listener member to the class.
Implement addXXXListener() and removeXXXListener().
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; ... |
Get Graphic Java™ 1.2, Volume I: AWT, Third Edition 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.