import java.applet.*;
import java.awt.*;
import java.awt.event.*; //For MouseListener
import sun.audio.*; //For sound
import java.io.*; //For sound
import java.io.FileInputStream.*; //For sound

public class ButtonExample_Sound extends Applet implements MouseListener
{


    public void mousePressed (MouseEvent e)
    {
	//get the x and y co-ordinates of the mouse
	int x = e.getX ();
	int y = e.getY ();

	//red button
	if (x > 100 && y > 50 && x < 150 && y < 100)
	{
	    soundEffect ("coin");
	}

    }


    public void paint (Graphics g)
    {
	g.setColor (Color.yellow);
	g.fillOval (100, 50, 50, 50);

    }


    //Other method needed for sound effect -------------------------------
    //For a single sound effect
    public void soundEffect (String filepath)
    {
	//initialize objects
	//declare sound effect player
	AudioPlayer SEP = AudioPlayer.player;
	//declare sound effect
	AudioStream SE;
	//declare audio data
	AudioData MA;
	//set as single run (NOT LOOP)
	AudioDataStream play = null;

	try
	{
	    //set file
	    SE = new AudioStream (new FileInputStream (filepath + ".wav"));
	    MA = SE.getData ();
	    //set data to play once (NOT LOOP)
	    play = new AudioDataStream (MA);
	}
	catch (IOException error)
	{
	    System.out.println ("Audio - File not found.");
	}
	SEP.start (play);
    }


    //Other Methods needed for MouseListener ------------------------------
    public void init ()
    {
	addMouseListener (this);
    }


    public void mouseClicked (MouseEvent e)
    {
    }


    public void mouseEntered (MouseEvent e)
    {
    }


    public void mouseExited (MouseEvent e)
    {
    }


    public void mouseReleased (MouseEvent e)
    {
    }


    //End of other methods needed for MouseListener ------------------
}
