I want to keep executing work while a button is pressed, using Java. When the button is released, the work should stop. Something like this:
Button_is_presse
You may need to use mousePressed event to start the action
mousePressed
And use mouseReleased event to stop the action (This is neccesary)
mouseReleased
For more information refer here