import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.applet.AudioClip; public class PlaySound extends JApplet implements ActionListener { private AudioClip sound; private JButton button; public void init() { sound = this.getAudioClip(getDocumentBase(), "bark.au"); button = new JButton("play"); Container container = getContentPane(); container.setLayout(new FlowLayout()); container.add(button); button.addActionListener(this); } public void actionPerformed(ActionEvent actionEvent) { if (actionEvent.getSource() == button) { /* sound.play(); //Play once. sound.loop(); //Play over and over again in a loop. sound.stop(); //Stop the sound loop. */ sound.play(); // or play(getDocumentBase(), "bark.au"); } } }