Java Reference
In-Depth Information
13.23
( Display a rectanguloid ) Write a program that displays a rectanguloid, as shown
in Figure 13.32c. The cube should grow and shrink as the frame grows or shrinks.
**13.24
( Game: bean machine ) Write a program that displays a bean machine intro-
duced in Programming Exercise 6.21. The bean machine should be centered in a
resizable panel, as shown in Figure 13.32d.
**13.25
( Geometry: display an n-sided regular polygon ) Define a subclass of JPanel ,
named RegularPolygonPanel , to paint an n -sided regular polygon. The class
contains a property named numberOfSides , which specifies the number of sides
in the polygon. The polygon is centered in the panel. The size of the polygon is
proportional to the size of the panel. Create a pentagon, hexagon, heptagon,
octagon, nonagon, and decagon from RegularPolygonPanel and display them
in a frame, as shown in Figure 13.33a.
(a)
(b)
(c)
F IGURE 13.33 (a) Exercise 13.25 displays several n-sided polygons. (b) Exercise 13.26 uses MessagePanel to display
four strings. (c) The polygon and its strategic point are displayed.
Sections 13.8-13.11
13.26
( Use the MessagePanel class) Write a program that displays four messages, as
shown in Figure 13.33b.
**13.27
( Geometry: strategic point of a polygon ) The strategic point of a polygon is a
point inside the polygon that has the shortest total distance to all vertices. Write
a program that finds and displays the strategic point, as shown in Figure 13.33c.
Your program should pass the coordinates of the polygon's vertices clockwise
from the command line as follows:
java Exercise13_27 x1 y1 x2 y2 x3 y3 . . .
The program displays the polygon and its strategic point in the frame. ( Hint : To
find the strategic point, consider every pixel point inside the polygon to see if it
is a strategic point. Use the contains method to check whether a point is inside
the polygon.)
**13.28
( Draw an arrow line ) Write a static method that draws an arrow line from a
starting point to an ending point using the following method header:
public static void drawArrowLine( int x1, int y1,
int x2, int y2, Graphics g)
Write a test program that randomly draws an arrow line, as shown in Figure
13.34a. Whenever you resize the frame, a new arrow line is drawn.
*13.29
( Two circles and their distance ) Write a program that draws two filled circles
with radius 15 pixels, centered at random locations, with a line connecting the
two circles. The distance between the two centers is displayed on the line, as
shown in Figure 13.34b-c. Whenever you resize the frame, the circles are redis-
played in new random locations.
 
 
Search WWH ::




Custom Search