//  File: PlayASound.java
//
//  Play a single sound when a button is pressed

import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.net.URL;

public class PlayASound extends Applet {

    /**
     *  Initialize the applet
     *    o Set up the button handler
     *    o Add the button to the screen
     *    o Access the 'phaser.au' sound
     */
    public void init() {
        setBackground(Color.BLUE);
        jbPlay.addActionListener(new PlayButtonHandler());
        add(new Label("                                          "));
        add(jbPlay);
        try {
            audio = getAudioClip(new URL(getDocumentBase(), "phaser.au"));
        } catch (Exception e) {
            System.err.println("Exception: " + e);
        }
    }

    /**
     *  Handle the click of the button -- play the sound
     */
    private class PlayButtonHandler implements ActionListener {
        public void actionPerformed(ActionEvent e) {
            audio.play();
        }
    }

    private Button jbPlay = new Button("      Click me to play 'phaser.au'      ");
    private AudioClip audio;

} // end class PlayAsound
