
hello
i have this code in the main:
try {
AudioInputStream audio = AudioSystem.getAudioInputStream(new File("x.wav"));
Clip clip = AudioSystem.getClip();
clip.open(audio);
clip.start();
}
catch(UnsupportedAudioFileException uae) {
System.out.println(uae);
}
catch(IOException ioe) {
System.out.println(ioe);
}
catch(LineUnavailableException lua) {
System.out.println(lua);
}
I want that when i press the stop button in the gui, the audio stops... please tell me what should i write in the action listener for the button
when i write clip.close(); it shows error
please help

Use the following code:
JButton button=new JButton("Stop");
button.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
clip.stop();
}
});
For the above,you need to import java.awt.event.* package

that is fine
but when i add the clip.stop(); it shows an eexception it thread error... in Netbeans.. it says" cannot find variable clip, create class clip , create field clip.... what should i do?