*16.24(Control a clock) Modify Listing 16.12, ClockAnimation.java, to add the twomethodsstart()andstop()to start and stop the clock. Write a programthat lets the user control the clock with the StartandStopbuttons, as shown inFigure 16.26d.
634Chapter 16Event-Driven Programming***16.25(Game: hit balloons) Write a program that displays a balloon in a randomposition in a panel (Figure 16.27a). Use the left- and right-arrow keys to pointthe gun left or right to aim at the balloon (Figure 16.27b). Press the up-arrowkey to fire a small ball from the gun (Figure 16.27c–d). Once the ball hits theballoon, the debris is displayed (Figure 16.27e) and a new balloon is dis-played in a random location (Figure 16.27f). If the ball misses the balloon, theball disappears once it hits the boundary of the panel. You can then press theup-arrow key to fire another ball. Whenever you press the left- or the right-arrow key, the gun turns 5 degrees left or right. (Instructors may modify thegame as follows: 1. Display the number of the balloons destroyed; 2. displaya countdown timer (e.g., 60 seconds) and terminate the game once the timeexpires; and/or 3. allow the balloon to rise dynamically.)**16.26(Move a circle using mouse) Write a program that displays a circle with radius 10pixels. You can point the mouse inside the circle and drag (i.e., move with mousepressed) the circle wherever the mouse goes, as shown in Figure 16.28a–b.***16.27(Game: eye-hand coordination) Write a program that displays a circle of radius10pixels filled with a random color at a random location on a panel, as shownin Figure 16.28c. When you click the circle, it disappears and a new random-color circle is displayed at another random location. After twenty circles areclicked, display the time spent in the panel, as shown in Figure 16.28d.(a)(b)(c)(d)(e)(f)FIGURE16.27(a) A balloon is displayed in a random location. (b) Press the left-/right-arrow keys to aim at the balloon. (c) Press the up-arrow key to fire a ball. (d) The ball movesstraight toward the balloon. (e) The ball hits the balloon. (f) A new balloon is displayed in arandom position.(a)(b)(c)(d)FIGURE16.28(a–b) You can point, drag, and move the circle. (c) When you click a circle, a new circle is displayed at arandom location. (d) After 20 circles are clicked, the time spent is displayed in the panel.
Programming Exercises635***16.28(Simulation: self-avoiding random walk) A self-avoiding walk in a lattice is apath from one point to another that does not visit the same point twice. Self-avoiding walks have applications in physics, chemistry, and mathematics.They can be used to model chain-like entities such as solvents and polymers.Write a program that displays a random path that starts from the center andends at a point on the boundary, as shown in Figure 16.29a, or ends at a dead-end point (i.e., surrounded by four points that have already been visited), asshown in Figure 16.29b. Assume the size of the lattice is 16by16.