public void playMet() {
int tempo = Integer.parseInt(met_speed.getText());
tempo = tempo/60;
int delay = tempo*1000;
if(Play.isSelected()) {
try {
FileInputStream in = new FileInputStream(new File("Click1.wav"));
AudioStream as = new AudioStream(in);
AudioPlayer.player.start(as);
Thread.sleep(tempo*1000);
playMet();
}
catch (Exception e) {
JOptionPane.showMessageDialog(null, e);
}
}
else
System.out.println("not playing");
}
Here's a section of my code, basically when a button is pressed it plays a click X times per minute.
I've tried the code with a while loop like this:
while(Play.isSelected()) {
.........
.........
}
and that didn't work either. In both cases the program runs like it should, but freezes and I have to close it down from the task manager.
How can I call a function when the button is pressed and be able to stop it if I deselect it?
P.S. Just saw the two posts below. Have to go to work, will check up on them later and see if they work. Thank you for the help.