Button doesnt work help
Hi
Below is the coding that i have created i am trying to make the button play a sound when it is pressed. It worked for one button but when i put the second button it doesnt work, any help will be greatly appreciated. Thanks
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.io.*;
import java.text.*;
import java.util.*;
import java.io.PrintStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.MalformedURLException;
import java.applet.AudioClip;
import java.net.URL;
public class Panel1 extends JPanel implements ActionListener
{
private JButton logout, open;
//AudioClip onceClip, loopClip;
//URL codeBase;
public Panel1()
{
//String [] fileTypes = {wavFile};
//public MalformedURLException();
//private URL("C:/JBuilder3/myprojects/untitled1/)
//throws MalformedURLException
logout = new JButton(" Logout ");
logout.addActionListener(this);
logout.setActionCommand("logout");
open = new JButton("Hello");
open.addActionListener(this);
open.setActionCommand("Hello");
JPanel controlPanel = new JPanel();
controlPanel.add(logout);
controlPanel.add(open);
add(controlPanel);
}
public void actionPerformed( ActionEvent evt )
{
// play a sound before loging out
try
{
if (logout == logout);
{
java.applet.AudioClip clip =
java.applet.Applet.newAudioClip(new java.net.URL("C:/JBuilder3/myprojects/untitled1/logout.wav"));
clip.play();
}
}
catch (MalformedURLException ex)
{
{
try
{
(open = open);
{
java.applet.AudioClip clip =
java.applet.Applet.newAudioClip(new java.net.URL("C:/JBuilder3/myprojects/untitled1/i.wav"));
clip.play();
}
}
catch (MalformedURLException pex)
{
}
}
}
}
public static void main(String s[]) {
WindowListener l = new WindowAdapter() {
public void windowClosing(WindowEvent e) {System.exit(0);}
};
JFrame f = new JFrame("Panel");
f.addWindowListener(l);
f.getContentPane().add(new Panel1());
//f.setSize(new Dimension(400,100));
f.show();
}
}
|