How can I keep executing work while a button is pressed?

后端 未结 3 1564
醉话见心
醉话见心 2021-01-13 09:25

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         


        
3条回答
  •  离开以前
    2021-01-13 10:10

    I want to keep executing work while a button is pressed

    Execute that process in another thread and then your form is not block and you can press the button to cancel or stop the execution.

    see :

    • How to stop threads of a Java program?
    • Stop/cancel SwingWorker thread?
    • Control thread through button

提交回复
热议问题