Dispatching Events and the AWT Event Queue

There are times when it is desirable to create an event and pass it to a specific component for handling. For instance, some applications may wish to record a sequence of events and play them them back at a later time. Essentially, there are two ways to send an event to a component: invoke Component.dispatchEvent() or use an event queue.

Component.dispatchEvent(AWTEvent) processes the event it is passed in the exact same manner as events that are initiated by user gestures. Figure 9-18 shows an applet that contains two buttons; when the button on the right is activated, mouse pressed and mouse released events are delivered to the button on the left. The mouse events cause the left-hand button to activate ...

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.