Sound
- The following code plays the
sound file “letitrock”
- The sound file needs to be
saved in the same folder as the code
- There are two parts to
playing a sound file (highlighted in blue)
import java.awt.*;
import java.applet.*;
import java.applet.Applet;
import javax.swing.*;
public class sound extends
Applet
{
AudioClip soundFile;
//the
input below is being called here
//the “AudioClip” part plays the song
when it is run
public void
init ()
{
soundFile = getAudioClip (getDocumentBase (), "letitrock.snd");
//this attaches the sound file “letitrock”
soundFile.loop ();
//put the sound on repeat
}
}
|