Owl Sams Teach Yourself Java 2 in 24 Hours

Hour 15: Playing Sound in an Applet

NOTES AND CORRECTIONS

  • On Page 240, the argument used with the JApplet.newAudioClip() method is incorrect. You must use a URL object to indicate the sound file to load into the AudioClip object (rather than a String). This URL should be preceded with the text file: to indicate that it is being loaded from a local file rather than a location on the Internet. Here's a revised example that creates an AudioClip object from a file called chachacha.wav in a subfolder named audio:
    • URL dance = new URL("file:audio/chachacha.wav");
    • AudioClip danceClip = JApplet.newAudioClip(dance);

SOURCE FILES

Using most browsers, you can save this hour's .wav files to disk (instead of playing them) by either holding down your SHIFT key as you click the .wav file's link or right-clicking the .wav file's link.

READER QUESTIONS

  • None

ACTIVITIES