Java Reference
In-Depth Information
Running in thread main
Working 0
Running in thread AWT-EventQueue-0
Working 1
Running in thread AWT-EventQueue-0
Working 2
Running in thread AWT-EventQueue-0
Working 3
Running in thread AWT-EventQueue-0
Working 4
Running in thread AWT-EventQueue-0
Working 5
Running in thread AWT-EventQueue-0
Working 6
Running in thread AWT-EventQueue-0
Working 7
Running in thread AWT-EventQueue-0
Working 8
Running in thread AWT-EventQueue-0
Working 9
Running in thread AWT-EventQueue-0
Let us analyse the observed behaviour. The following list shows what happens in
chronological order.
1. When the menu is clicked, a command to repaint the GUI with the rolled-out
menu is added at the end of the event queue. Some time after the command has
been executed the menu becomes visible. The repaint command is removed
from the queue.
2. When the menu item 'Start' is selected, a call to the method actionPerformed
is added to the event queue.
3. A command to redraw the GUI with the retracted menu is added to the queue,
behind the call to actionPerformed .
4. In every iteration of the for loop a command to redraw the label with the
updated text is added to the queue, behind the repaint command.
By the first-in-first-out property of the queue the events in 3 and 4 can be processed
only after the event in 2 by the event thread. In particular, the lengthy action-
Performed method is run in the event thread and hinders it from processing the
following events. Until actionPerformed terminates, the GUI is not updated and
shows the rolled-out menu. Also the label and menu bar are not repainted when
the frame is resized. The repaint requests are added at the end of the event queue
where they wait to come to the head. Further events from the GUI occurring during
this time, such as mouse clicks, are added to the event queue. They all have to wait
until the previously added requests have been processed, especially the lengthy
actionPerformed in 2. As no reaction to these events happens during that time,
Search WWH ::




Custom Search