ex 12 cards
COSC1047 (Game: displaying three cards) Display a frame that contains three labels. Each label displays a card, as shown in Figure 12.16(b). The card image files are named
1.png, 2.png, 54.png and stored in the image/card directory. All three cards are distinct and selected randomly.
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.
FIGURE 12.26 Exercise 12.1 places the first three buttons in one panel and the other three
buttons in another panel.
(a) (b) (c)
FIGURE 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.
download image files
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.
12 years ago
Purchase the answer to view it

- excercise12_1_answer.zip