Instead GUI models require an event approach. Each user action, be
it a mouse click, a key press, or something else is placed in an
event queue as it occurs. Normally this takes place at
the operating system level. The program removes events from the
queue and processes them, one at a time. Generally an infinite
while
loop reads from the queue, and a big
switch
statement dispatches each different event to the
appropriate code to handle it.
Depending on the architecture of the system, there may be only one system event queue or each application may have its own event queue. The operating system is responsible for making sure the right events get to the right programs.
In the applications we're concerned with, that is Java programs, each virtual machine has one main AWT event queue. There's almost certainly a native event queue as well, but from here on out I'll only talk about the Java event queue. Your Java program will only see events that are sent to it by the native queue.