java.awt.Component.dispatchEvent()'s purpose and behavior

Kaleb Pederson picture Kaleb Pederson · Jan 20, 2010 · Viewed 9.3k times · Source

Most of the tutorials and documentation that 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?

Answer

Tom Hawtin - tackline picture Tom Hawtin - tackline · Jan 20, 2010

The component has to receive the events to dispatch somewhere. This is where a component receives the events. The events come from the EventQueue.