java.awt.Component.dispatchEvent()'s purpose and behavior
Most of the tutorials and documentation 开发者_如何学JAVAthat I've been reading seem to indicate that most component communication takes place by subscription using listeners.
The Java docs indicate that java.awt.Component#dispatchEvent(AWTEvent e)
:
Dispatches an event to this component or one of its sub components. Calls processEvent before returning for 1.1-style events which have been enabled for the Component.
Given that listeners seem commonplace, what is the purpose of dispatchEvent
and how / where is the dispatched event received?
The component has to receive the events to dispatch somewhere. This is where a component receives the events. The events come from the EventQueue
.
I researched how to send custom events to a JFrame, and finally I succeeded in compiling some examples found on the web.
The functional result is visible here:
link text
Hoping that it might be useful!
Serge COUDÉ
精彩评论