samedi 29 novembre 2014

java JToggleButton freezes in while loop


Vote count:

0





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?



asked 1 min ago







java JToggleButton freezes in while loop

Aucun commentaire:

Enregistrer un commentaire