[Solved] When I run my autoclicker I can’t stop it


Swing is single threaded – calling any long running task on that thread will lock that thread up (the EDT) and prevent any painting, events, etc… from occurring. One of the ActionListener implementations creates an infinite loop:

while(chckbxAutoclicker.isSelected()){

The above will never evaluate to false, because it is evaluating on the EDT, and events (such as disabling the JCheckBox to allow this method to return false) cannot occur until the EDT is free. If you wish to continually run a task while allowing the EDT to performs its necessary tasks, you have three options:

  1. Create a new Thread. Note any calls to Swing from this thread should be dispatched to the EDT using SwingUtilities.invoke*
  2. Use a SwingWorker
  3. If you wish to do something at a later time on the EDT, or run something on a schedule on the EDT, use a javax.swing.Timer

0

solved When I run my autoclicker I can’t stop it