Java Reference
In-Depth Information
MultipleWindowsDemo class also contains an instance of JFrame , named
histogramFrame (line 8), which holds an instance of Histogram . When the user clicks the
Show Histogram button, histogramFrame is set as visible to display the histogram (line 35).
The height and width of the bars in the histogram are determined dynamically according to
the window size of the histogram.
You cannot add an instance of JFrame to a container. For example, adding
histogramFrame to the main frame would cause a runtime exception. However, you can
create a frame instance and set it visible to launch a new window.
Check
Point
17.23 Explain how to create and show multiple windows in an application.
C HAPTER S UMMARY
1.
You learned how to handle events for JCheckBox , JRadioButton , and
JTextField .
2.
You learned how to create graphical user interfaces using the Swing GUI components
JTextArea , JComboBox , JList , JScrollBar , and JSlider . You also learned
how to handle events on these components.
3.
You learned how to launch multiple windows using JFrame .
T EST Q UESTIONS
Do the test questions for this chapter online at www.cs.armstrong.edu/liang/intro9e/test.html .
P ROGRAMMING E XERCISES
Sections 17.2-17.5
*17.1
( Use radio buttons ) Write a GUI program as shown in Figure 17.17. You can use
buttons to move the message left and right and use the radio buttons to change the
background color for the message displayed in the message panel.
F IGURE 17.17 The and buttons move the message on the panel, and the radio but-
tons change the background color for the message.
6=
= 7
*17.2
( Select geometric figures ) Write a program that draws various figures, as shown in
Figure 17.18. The user selects a figure from a radio button and uses a check box to
specify whether it is filled. ( Hint : Use the FigurePanel class introduced in
Listing 13.3 to display a figure.)
**17.3
( Traffic lights ) Write a program that simulates a traffic light. The program lets the
user select one of three lights: red, yellow, or green. When a radio button is selected,
the light is turned on, and only one light can be on at a time (see Figure 17.19). No
light is on when the program starts.
 
 
Search WWH ::




Custom Search