Java Reference
In-Depth Information
**15.18
( Move a rectangle using mouse ) Write a program that displays a rectangle.
You can point the mouse inside the rectangle and drag (i.e., move with mouse
pressed) the rectangle wherever the mouse goes. The mouse point becomes the
center of the rectangle.
**15.19
( Game: eye-hand coordination ) Write a program that displays a circle of radius
10 pixels filled with a random color at a random location on a pane, as shown
in Figure 15.29b. When you click the circle, it disappears and a new random-
color circle is displayed at another random location. After twenty circles are
clicked, display the time spent in the pane, as shown in Figure 15.29c.
**15.20
( Geometry: display angles ) Write a program that enables the user to drag the verti-
ces of a triangle and displays the angles dynamically as the triangle shape changes,
as shown in Figure 15.30a. The formula to compute angles is given in Listing 4.1.
(a)
(b)
F IGURE 15.30
(a) Exercise 15.20 enables the user to drag vertices and display the angles
dynamically. (b) Exercise 15.21 enables the user to drag vertices along the circle and display
the angles in the triangle dynamically.
*15.21 ( Drag points ) Draw a circle with three random points on the circle. Connect
the points to form a triangle. Display the angles in the triangle. Use the mouse
to drag a point along the perimeter of the circle. As you drag it, the triangle and
angles are redisplayed dynamically, as shown in Figure 15.30b. For computing
angles in a triangle, see Listing 4.1.
Section 15.10
*15.22 ( Auto resize cylinder ) Rewrite Programming Exercise 14.10 so that the cylin-
der's width and height are automatically resized when the window is resized.
*15.23 ( Auto resize stop sign ) Rewrite Programming Exercise 14.15 so that the stop
sign's width and height are automatically resized when the window is resized.
Section 15.11
**15.24
( Animation: palindrome ) Write a program that animates a palindrome swing as
shown in Figure 15.31. Press/release the mouse to pause/resume the animation.
F IGURE 15.31
The program animates a palindrome swing.
 
Search WWH ::




Custom Search