Java Reference
In-Depth Information
F IGURE 16.33
The program animates a ball travelling along a sine curve.
(a)
(b)
(c)
(d)
F IGURE 16.34 (a-b) Exercise 16.36 enables the user to click a cell to flip a coin. (c) The user can drag the circles.
(d) Exercise 16.38 draws an arrow line randomly.
with the mouse listener for handling the clicks. When the program starts, all
cells initially display H .
*16.37
( Two movable vertices and their distances ) Write a program that displays two
circles with radius 20 at location ( 20 , 20 ) and ( 120 , 50 ) with a line connect-
ing the two circles, as shown in Figure 16.34c. The distance between the cir-
cles is displayed along the line. The user can drag a circle. When that
happens, the circle and its line are moved and the distance between the circles
is updated. Your program should not allow the circles to get too close. Keep
them at least 70 pixels apart between the two circles' centers.
**16.38
( 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 when the Draw a Ran-
dom Arrow Line button is clicked, as shown in Figure 16.34d.
**16.39
( Geometry: find the bounding rectangle ) Write a program that enables the
user to add and remove points in a two-dimensional plane dynamically, as
shown in Figure 16.35a-b. A minimum bounding rectangle is updated as the
points are added and removed. Assume the radius of each point is 10 pixels.
*16.40
( Display random 0 or 1 ) Write a program that displays a 10-by-10 square matrix,
as shown in Figure 16.35c. Each element in the matrix is 0 or 1, randomly gen-
erated with a click of the Refresh button. Display each number centered in a
label.
 
Search WWH ::




Custom Search