Java Reference
In-Depth Information
10.
You can specify the horizontal and vertical text position relative to the icon in
JButton , JCheckBox , JRadioButton , and JLabel .
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
Note
The image icons used in the exercises can be obtained from
www.cs.armstrong.edu/liang/intro9e/book.zip under the image folder.
download image files
Sections 12.2-12.6
12.1
( Use the FlowLayout manager ) Write a program that meets the following
requirements (see Figure 12.26):
Create a frame and set its layout to FlowLayout .
Create two panels and add them to the frame.
Each panel contains three buttons. The panel uses FlowLayout .
F IGURE 12.26 Exercise 12.1 places the first three buttons in one panel and the other three
buttons in another panel.
12.2
( Use the BorderLayout manager ) Rewrite the preceding program to create
the same user interface, but instead of using FlowLayout for the frame, use
BorderLayout . Place one panel in the south of the frame and the other in the
center.
12.3
( Use the GridLayout manager ) Rewrite Programming Exercise 12.1 to add six
buttons into a frame. Use a GridLayout of two rows and three columns for the
frame.
12.4
( Use JPanel to group buttons ) Rewrite Programming Exercise 12.1 to create the
same user interface. Instead of creating buttons and panels separately, define a
class that extends the JPanel class. Place three buttons in your panel class, and
create two panels from the user-defined panel class.
12.5
( Display labels ) Write a program that displays four lines of text in four labels, as
shown in Figure 12.27a. Add a line border around each label.
(a) (b) (c)
F IGURE 12.27 (a) Exercise 12.5 displays four labels. (b) Exercise 12.6 displays four icons.
(c) Exercise 12.7 displays a tic-tac-toe board with image icons in labels.
 
 
Search WWH ::




Custom Search