title: Exiting an infinite loop with a button - Java
body: <p>I've searched for a solution for my problem all over but I cannot find anything close. Here is my problem: I have just started to learn Swing in Java and I have an application that will click randomly between a min and max amount of time. The user enters a min and max time and clicks a button which starts this code:</p>
  
  <pre><code>    class CalcButtonListener implements ActionListener{
  
      @Override
      public void actionPerformed(ActionEvent arg0) {
          //get data from text fields and store as integers in milliseconds. 
  
          //create a robot and random number between min and max
  
          while(run == true){
  
              robot.mousePress(InputEvent.BUTTON1_MASK);
              robot.mouseRelease(InputEvent.BUTTON1_MASK);
              robot.delay(num.nextInt(max-min+1)+min);
  
              }
          }
      }
  }
  </code></pre>
  
  <p>I've removed some code because it wasn't relevant to the issue.
  The problem is I have another button to set the variable run to false but once the first button is clicked, I can't click the second button or the exit button at the top for that matter.</p>
  
  <p>I'm sure my mistake is a very basic one but I can't see it.
  Thank you for any replies that help me better understand the subject.</p>
  
  <p>Edit: Changed the while loop from "while (run = true)" to "while (run == true)".</p>