13.11. Case Study - The MessagePanel Class

 
[Page 423 ( continued )]

Programming Exercises

Section 12.5 Layout Managers

12.1 ( Using the FlowLayout manager ) Write a program that meets the following requirements (see Figure 12.16):
  • 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.16. Exercise 12.1 places three buttons in one panel and three buttons in another panel.

12.2 ( Using 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 panel in the center.
12.3 ( Using the GridLayout manager ) Rewrite the preceding program to create the same user interface. Instead of using FlowLayout for the panels, use a GridLayout of two rows and three columns .
12.4 ( Using JPanel to group buttons ) Rewrite the preceding program 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 ( Displaying labels ) Write a program that displays four lines of text in four labels, as shown in Figure 12.17(a). Add a line border on each label.
Figure 12.17. (a) Exercise 12.5 displays four labels. (b) Exercise 12.6 displays four icons.
(This item is displayed on page 424 in the print version)


12.6 ( Displaying icons ) Write a program that displays four icons in four labels, as shown in Figure 12.17(b). Add a line border on each label. (Use any images of your choice or the ones in the book, which can be obtained along with the book's source code).

[Page 424]
12.7** ( Displaying a TicTacToe board ) Display a frame that contains nine labels. A label may display a cross image icon, a not image icon, or nothing, as shown in Figure 12.18(a). What to display is randomly decided. Use the Math.random() method to generate an integer 0, 1, or 2, which corresponds to displaying a cross image icon, a not image icon, or nothing. The cross and not images can be obtained from the cross.gif and not.gif files in the image directory on the Companion Website.
Figure 12.18. (a) A TicTacToe board is displayed with image icons in labels. (b) Six labels are placed in the frame.


12.8* ( Swing common features ) Display a frame that contains six labels. Set the background 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.18(b). Set the border of each label to a line border with the yellow color . Set the font of each label to TimesRoman, bold, and 20 pixels. Set the text and tool tip text of each label to the name of its foreground color.
 


Introduction to Java Programming-Comprehensive Version
Introduction to Java Programming-Comprehensive Version (6th Edition)
ISBN: B000ONFLUM
EAN: N/A
Year: 2004
Pages: 503

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net