checking for an event during an event
Say you click a button which loops a process, but you want to terminate that process when you click the button again, or press some key.
So for example, I registered the listener object with the button. When I press the button, it triggers an ActionEvent and goes to the actionPerformed method wherein it loops some process. I want to make it so that the loops ends if the user decides to press a key(or something else that triggers an event).
How do you do that?