When the operating environment generates an event in response to a user action such as a mouse click, the part of the AWT that communicates with the operating environment receives a notification and turns it into an AWT event. The AWT then deposits the event into an event queue. The part of the AWT that dispatches events to listeners:

An event queue is important for performance reasons. Events that occur frequently (such as mouse moves) or that are slow to carry out (such as painting) can be combined in the queue. If the program has not managed to extract mouse move or paint events and a new event is inserted, then the AWT can combine it with the existing event to make a single, new event. For example, we can have the new mouse position update the old one, or a new paint event can contain a request to repaint the combined areas of the old paint events. Occasionally, it is useful to manipulate the event queue directly. For example, you can remove events from the queue, thereby bypassing how events would normally be delivered. Or, you can add new events into the queue, allowing a richer event handling than is possible in the basic Java event model. You obtain an object representing the event queue by using the method call

EventQueue queue
 = Toolkit.getDefaultToolkit().getSystemEventQueue();

You insert a new event into the event queue with the postEvent method:

queue.postEvent(new ActionEvent(this,
 ActionEvent.ACTION_PERFORMED, "Blue"));

You remove an event with the getNextEvent method. The peekEvent method returns the next event in the queue, but it does not remove it.Java graphics notes_icon

Inserting or removing events is an advanced technique. If performed improperly or maliciously, it can wreak havoc with an app. For that reason, applets-the Java apps that are downloaded from foreign computers and run inside your browser-are not allowed access to the system event queue.

java.awt.EventQueue 1.1

Java graphics api_icon