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.

<strong>Programming</strong> Exercises 703<br />

(a)<br />

FIGURE 18.25 (a) The applet allows you <strong>to</strong> add or remove bouncing balls. (b) Click Play <strong>to</strong><br />

play an audio clip once, click Loop <strong>to</strong> play an audio repeatedly, and click S<strong>to</strong>p <strong>to</strong> terminate<br />

playing.<br />

(b)<br />

*18.20 (Play, loop, and s<strong>to</strong>p a sound clip) Write an applet that meets the following<br />

requirements:<br />

■ Get an audio file from the class direc<strong>to</strong>ry.<br />

■ Place three but<strong>to</strong>ns labeled Play, Loop, and S<strong>to</strong>p, as shown in Figure 18.25b.<br />

■ If you click the Play but<strong>to</strong>n, the audio file is played once. If you click the<br />

Loop but<strong>to</strong>n, the audio file keeps playing repeatedly. If you click the S<strong>to</strong>p<br />

but<strong>to</strong>n, the playing s<strong>to</strong>ps.<br />

■ The applet can run as an application.<br />

**18.21 (Create an alarm clock) Write an applet that will display a digital clock with a<br />

large display panel that shows the hour, minute, and second. This clock should<br />

allow the user <strong>to</strong> set an alarm. Figure 18.26a shows an example of such a clock.<br />

To turn on the alarm, check the Alarm check box. To specify the alarm time,<br />

click the Set alarm but<strong>to</strong>n <strong>to</strong> display a new frame, as shown in Figure 18.26b.<br />

You can set the alarm time in the frame.<br />

(a)<br />

(b)<br />

FIGURE 18.26 The program displays the current hour, minute, and second and enables you<br />

<strong>to</strong> set an alarm.<br />

**18.22 (Create an image anima<strong>to</strong>r with audio) Create animation using the applet<br />

shown in Figure 18.27 <strong>to</strong> meet the following requirements:<br />

■ Allow the user <strong>to</strong> specify the animation speed in a text field.<br />

■ Get the number of frames and the image’s file-name prefix from the user.<br />

For example, if the user enters n for the number of frames and L for the<br />

image prefix, then the files are L1, L2, and so on, <strong>to</strong> Ln. Assume that the<br />

images are s<strong>to</strong>red in the image direc<strong>to</strong>ry, a subdirec<strong>to</strong>ry of the applet’s<br />

direc<strong>to</strong>ry.<br />

■ Allow the user <strong>to</strong> specify an audio file name. The audio file is s<strong>to</strong>red in the<br />

same direc<strong>to</strong>ry as the applet. The sound is played while the animation runs.

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

Saved successfully!

Ooh no, something went wrong!