Java Reference
In-Depth Information
(a)
(b)
(c)
F
IGURE
13.26
(a) Exercise 13.1 displays a grid. (b) Exercise 13.2 displays two objects of
OvalButton
. (c) Exercise 13.3 displays a checkerboard.
**13.5
(
Display numbers in a triangular pattern
) Write a program that displays numbers
in a triangular pattern, as shown in Figure 13.27b. The number of lines in the dis-
play changes to fit the window as the window resizes.
(a) (b)
F
IGURE
13.27
(a) Exercise 13.4 displays a multiplication table. (b) Exercise 13.5 displays
numbers in a triangle formation.
**13.6
(
Improve
FigurePanel
)
The
FigurePanel
class in Listing 13.3 can display
lines, rectangles, round-cornered rectangles, and ovals. Add appropriate
new code in the class to display arcs and polygons. Write a test program to
display the shapes as shown in Figure 13.28a using the new
FigurePanel
class.
**13.7
(
Display a tic-tac-toe board
) Create a custom panel that displays
X
,
O
, or nothing.
What to display is randomly decided whenever a panel is repainted. Use the
Math.random()
method to generate an integer
0
,
1
, or
2
, which corresponds to
displaying
X
,
O
, or nothing. Create a frame that contains nine custom panels, as
shown in Figure 13.28b.
**13.8
(
Draw an octagon
) Write a program that draws an octagon, as shown in
Figure 13.28c.