Looping until keypress. How is this done?
Let me give context.
I'm writing a program that uses JFugue, and I want it to loop a particular pattern over and over again until the user presses a key on the keyboard (anyone not familiar with JFugue: play a tune over and over again).
Now, I'm using keylisteners like a good programmer, now, the problem is how can I tell the loop to keep going until a keyevent is received by the listener? I've been looking for an answer pretty well everyone and haven't found anything close to this dilemma. I'm getting many "take input until someone types 'quit'" kind of problems, which I know how to code, but that isn't what I am looking for. The program isn't waiting for input before doing something, its doing something until it receives input.
Re: Looping until keypress. How is this done?
Have the loop test a boolean variable and exit the loop when its value changes. Your loop should be careful to not use the GUI's thread.
how can I tell the loop to keep going until a keyevent is received by the listener?
Use a key listener or keybinding to set the boolean variable when the key is pressed.