I am attempting to create a simple applet that plays an audio file when a play or loop button is clicked and then stops when stop is clicked. However for some reason my event handling is not working properly and I cannot figure out why.
Here is my code:
import java.applet.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JApplet;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import javax.swing.border.EmptyBorder;
public class JWater extends JApplet {
public void init()
{
    sound = getAudioClip(getCodeBase(),"water001.au"); //Set audio file
    //Prepare to try and create GUI
    try
    {
        SwingUtilities.invokeAndWait(new Runnable()
        {
            public void run()
            {                   
                makeGUI(); //Create the GUI                         
            }
        });
    }
    catch (Exception e)
    {
        System.err.println("GUI was not created successfully"); //In case something goes wrong
    }               
}
private void makeGUI() {
    //Create content pane which everything will reside in
    setBounds(100, 100, 317, 189);
    contentPane = new JPanel();
    contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
    setContentPane(contentPane);
    contentPane.setLayout(null);
    setVisible(true);
    //Create and add panel, buttons and the label will be added to this 
    JPanel panel = new JPanel();
    panel.setBounds(0, 0, 300, 150);
    contentPane.add(panel);
    panel.setLayout(null);
    //Create and add the label
    JLabel lblNewLabel = new JLabel("This is the sound of flowing water.");
    lblNewLabel.setBounds(54, 46, 250, 14);
    panel.add(lblNewLabel);
    jOP = new JOptionPane();
    jOP.setBounds(10,40,250,10);
    panel.add(jOP);
    //Create and add media control buttons      
    JButton btnPlay = new JButton("Play");
    btnPlay.setBounds(10, 116, 89, 23);
    panel.add(btnPlay);
    JButton btnLoop = new JButton("Loop");
    btnLoop.setBounds(109, 116, 89, 23);
    panel.add(btnLoop);
    JButton btnStop = new JButton("Stop");
    btnStop.setBounds(208, 116, 89, 23);
    panel.add(btnStop);
    //Create an event handler named handler
    EventHandler handler = new EventHandler();
    //Add these action listeners to detect when a button is clicked
    btnPlay.addActionListener(handler);
    btnLoop.addActionListener(handler);
    btnStop.addActionListener(handler);
}
//Implement the event handler class for button clicks
    class EventHandler implements ActionListener
    {       
        public void actionPerformed(ActionEvent event)
        {
            if (event.getSource() == btnPlay)   
            {
            }
            else if (event.getSource() == btnLoop)  
            {
            }
            else if (event.getSource() == btnStop)  
            {                           
            }
            else
            {           
                JOptionPane.showMessageDialog(null,"Message not detected or not sent!!!  Recevied " + event.getSource(),"ERROR CODE 1",JOptionPane.ERROR_MESSAGE);
            }
        }       
    }
    AudioClip sound;
    JPanel contentPane,panel;
    JButton btnPlay,btnLoop,btnStop;
    JOptionPane jOP;
}
When ever a button is clicked it sails through my if statements and lands on else in the debugger. I think there may be something wrong within the EventHandler class but I am not sure where it is. I have used this method in other programs and it works just fine but not with this one.
 
     
  
  
    