Java Reference
In-Depth Information
Sections 12.7-12.15
12.6
( Display icons ) Write a program that displays four icons in four labels, as shown
in Figure 12.27b. Add a line border around each label.
**12.7
( Game: display a tic-tac-toe board ) Display a frame that contains nine labels. A
label may display an image icon for X or an image icon for O, as shown in
Figure 12.27c. What to display is randomly decided. Use the Math.random()
method to generate an integer 0 or 1 , which corresponds to displaying an X or O
image icon. These images are in the files x.gif and o.gif .
*12.8
( Swing common features ) Display a frame that contains six labels. Set the back-
ground of the labels to white. Set the foreground of the labels to black, blue, cyan,
green, magenta, and orange, respectively, as shown in Figure 12.28a. Set the bor-
der of each label to a line border with the color yellow. Set the font of each label to
Times Roman, bold, and 20 pixels. Set the text and tool tip text of each label to the
name of its foreground color.
(a) (b) (c)
F IGURE 12.28 (a) Six labels are placed in the frame. (b) Three cards are randomly selected.
(c) A checkerboard is displayed using buttons.
*12.9
( Game: display three cards ) Display a frame that contains three labels. Each label
displays a card, as shown in Figure 12.28b. The card image files are named 1.png ,
2.png , . . ., 54.png (including jokers) and stored in the image/card directory. All
three cards are distinct and selected randomly.
*12.10
( Game: display a checkerboard ) Write a program that displays a checkerboard in
which each white and black cell is a JButton with a background black or white,
as shown in Figure 12.28c.
VideoNote
Display a checkerboard
*12.11
( Game: display four cards ) Use the same cards from Exercise 12.9 to display a
frame that contains four buttons. All buttons have the same icon from
backCard.png , as shown in Figure 12.29a. The pressed icons are four cards ran-
domly selected from the 54 cards in a deck, as shown in Figure 12.29b.
(a)
F IGURE 12.29 (a) The four buttons have the same icon. (b) Each button's pressed icon is randomly picked from the
deck. (c) The image icons and texts are displayed in four labels.
(b)
(c)
 
Search WWH ::




Custom Search