views:

637

answers:

1

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?

+2  A: 

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

Tom Hawtin - tackline
So this would likely be used internally by Java as it notices an event coming in from the OS/Gui system, such as native mouse clicks, etc., and not for inter-component communication where you have full programmatic control over the events?
Kaleb Pederson
How do you mean? It's not for day-to-day code. And you can't override it.
Tom Hawtin - tackline
In other words, I really don't need to use it because I can create my own events and event listeners. The raw AWT code may use it to dispatch certain events, but I need not concern myself with it because I will be notified of the events through some listener where relevant.
Kaleb Pederson