19.09.2015 Views

Prentice.Hall.Introduction.to.Java.Programming,.Brief.Version.9th.(2014).[sharethefiles.com]

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

636 Chapter 16 Event-Driven <strong>Programming</strong><br />

(a) (b) (c)<br />

FIGURE 16.30 Clicking the + ˛1 or - ˛1 but<strong>to</strong>n increases or decreases the number of sides of<br />

a regular polygon in Exercise 16.31. Exercise 16.32 allows the user <strong>to</strong> create/remove points<br />

dynamically.<br />

FIGURE 16.31<br />

Exercise 16.33 animates a pendulum swinging.<br />

**16.34 (Game: hangman) Write a program that animates a hangman game swinging,<br />

as shown in Figure 16.32. Press the UP arrow key <strong>to</strong> increase the speed and<br />

the DOWN arrow key <strong>to</strong> decrease it. Press the S key <strong>to</strong> s<strong>to</strong>p animation and the<br />

R key <strong>to</strong> resume it.<br />

FIGURE 16.32<br />

The program animates a hangman game swinging.<br />

***16.35 (Animation: ball on curve) Write a program that animates a ball moving along<br />

a sine curve, as shown in Figure 16.33. When the ball gets <strong>to</strong> the right border,<br />

it starts over from the left. Enable the user <strong>to</strong> resume/pause the animation with<br />

a click on the left/right mouse but<strong>to</strong>n.<br />

*16.36 (Flip coins) Write a program that displays heads (H) or tails (T) for each of<br />

nine coins, as shown in Figure 16.34a–b. When a cell is clicked, the coin is<br />

flipped. A cell is a JLabel. Write a cus<strong>to</strong>m cell class that extends JLabel

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!