Chapter 14: Problem 35
What Applet method can you use to play a sound file?
Short Answer
Expert verified
Answer: The method used in an Applet to play a sound file is the 'play' method, which has the following signature: `public void play(URL url)`. It takes a URL as an argument representing the location of the sound file to be played. An example of its usage is as follows:
```java
import java.applet.*;
import java.net.*;
public class SoundApplet extends Applet {
public void init() {
try {
URL soundFile = new URL(getCodeBase(), "soundFile.wav");
play(soundFile);
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
}
```
In this example, the 'play' method is called in the 'init()' method of the applet, automatically playing the sound file 'soundFile.wav' located in the same directory as the applet's code.