how events are dispatched from event queue

635 Views Asked by At

I read a statement in Java docs related to event queue saying that "note that events being posted to the eventQueue can be coalesced" . What is the meaning of this line?

1

There are 1 best solutions below

1
On

http://docs.oracle.com/javase/7/docs/api/java/awt/EventQueue.html

postEvent

public void postEvent(AWTEvent theEvent)

Posts a 1.1-style event to the EventQueue. If there is an existing event on the queue with the same ID and event source, the source Component's coalesceEvents method will be called.

Parameters: theEvent - an instance of java.awt.AWTEvent, or a subclass of it Throws: NullPointerException - if theEvent is null

http://docs.oracle.com/javase/7/docs/api/java/awt/Component.html

coalesceEvents

protected AWTEvent coalesceEvents(AWTEvent existingEvent,
                                  AWTEvent newEvent)

Potentially coalesce an event being posted with an existing event. This method is called by EventQueue.postEvent if an event with the same ID as the event to be posted is found in the queue (both events must have this component as their source). This method either returns a coalesced event which replaces the existing event (and the new event is then discarded), or null to indicate that no combining should be done (add the second event to the end of the queue). Either event parameter may be modified and returned, as the other one is discarded unless null is returned.

This implementation of coalesceEventscoalesces two event types: mouse move (and drag) events, and paint (and update) events. For mouse move events the last event is always returned, causing intermediate moves to be discarded. For paint events, the new event is coalesced into a complex RepaintArea in the peer. The new AWTEvent is always returned.

Parameters: existingEvent - the event already on the EventQueue newEvent - the event being posted to the EventQueue Returns: a coalesced event, or null indicating that no coalescing was done