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 user interface.