2

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?

Kaleb Pederson
  • 45,767
  • 19
  • 102
  • 147

2 Answers2

1

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
  • 145,806
  • 30
  • 211
  • 305
  • 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 Jan 20 '10 at 19:16
  • How do you mean? It's not for day-to-day code. And you can't override it. – Tom Hawtin - tackline Jan 20 '10 at 19:28
  • 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 Jan 20 '10 at 20:30
0

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É

scoude
  • 9
  • 1