Java Reference
In-Depth Information
is changed to Pause , as shown in Figure 18.33b. When the user clicks the
Pause button, the button's label is changed to Resume , as shown in Figure
18.33c. The Clear button resets the count to 0 and resets the button's label
to Start .
*18.32
( Count-down stopwatch ) Write an applet that allows the user to enter time in
seconds in the text field and press the Enter key to count down the minutes,
as shown in Figure 18.33(d). The remaining seconds are redisplayed every
one second. When the minutes are expired, the program starts to play music
continuously.
**18.33
( Pattern recognition: consecutive four equal numbers ) Write an applet for
Programming Exercise 7.19, as shown in Figure 18.34a-b. Let the user enter
the numbers in the text fields in a grid of 6 rows and 7 columns. The user can
click the Solve button to highlight a sequence of four equal numbers, if it
exists.
(a) (b) (c)
F IGURE 18.34 (a)-(b) Clicking the Solve button to highlight the four consecutive numbers
in a row, a column, or a diagonal. (c) The applet enables two players to play the connect-four
game.
***18.34
( Game: connect four ) Programming Exercise 7.20 enables two players to play
the connect-four game on the console. Rewrite the program using an applet, as
shown in Figure 18.34c. The applet enables two players to place red and yel-
low discs in turn. To place a disk, the player needs to click on an available cell.
An available cell is unoccupied and its downward neighbor is occupied. The
applet flashes the four winning cells if a player wins and reports no winners if
all cells are occupied with no winners.
***18.35
( Game: play connect four with computer ) Revise Exercise 18.34 to play the
game with the computer. The program lets the user make a move first, fol-
lowed by a move by the computer. The minimum requirement is for the com-
puter to make a legal move. You are encouraged to design good strategies for
the computer to make intelligent moves.
**18.36
( Geometry: display angles ) Write a program that enables the user to drag the
vertices of a triangle and displays the angles dynamically as the triangle shape
changes, as shown in Figure 18.35a. Change the mouse cursor to the cross-hair
shape when the mouse is moved close to a vertex. The formula to compute
angles A, B, and C are as follows (see Figure 18.35b):
A = Math.acos((a * a - b * b - c * c) / ( -2 * b * c))
B = Math.acos((b * b - a * a - c * c) / ( -2 * a * c))
C = Math.acos((c * c - b * b - a * a) / ( -2 * a * b))
 
Search WWH ::




Custom Search