Java Reference
In-Depth Information
(a)
(b)
Figure 20.1 The results of applications (a)
BlockingFrame
and (b)
NonBlockingFrame
the GUI appears to be blocked. The console output commands are operations that
do not require any graphical components and are not put into the event queue.
Therefore they are performed right away and appear as expected. The code for
BlockingFrame
is listed below and the resulting display is shown in Figure 20.1.
File:
its/Blocking/BlockingFrame.java
package
its.Blocking;
1.
2.
3.
import
its.SimpleFrame.SimpleFrame;
4.
import
java.awt.event.ActionEvent;
5.
import
java.awt.event.ActionListener;
6.
import
javax.swing.JLabel;
7.
import
javax.swing.JMenu;
8.
import
javax.swing.JMenuBar;
9.
import
javax.swing.JMenuItem;
10.
11.
public class
BlockingFrame
extends
SimpleFrame
12.
{
13.
14.
private
JLabel display;
15.
16.
public
BlockingFrame(){
17.
display =
new
JLabel("Nothing happened");
this
.getContentPane().add(display);
18.
19.
20.
JMenuBar menuBar
=
new
JMenuBar();
this
.setJMenuBar(menuBar);
21.
JMenu
menu
=
new
JMenu("Menu1");
22.
menuBar.add(menu);
23.
JMenuItem startItem =
new
JMenuItem("Start");
24.
Search WWH ::
Custom Search