title: How to stop a loop with a button?
body: <p>I am writing a program which starts a loop when start button is clicked and I want to stop it with a stop button. Problem is when loop starts buttons do not work until loop is complete. 
  I've searched similar questions and understood the problem is loop is in actionPerformed but I couldn't manage to take the loop outside of the actionPerformed. 
  I've tried that to make a new class and call for it etc but exactly same thing happened.
  By the way I am a beginner at Java also stackoverflow and I am sorry if I did something wrong.<br>
  simply code: </p>
  
  <pre><code>OtherClass obj;
  public void actionPerformed(ActionEvent e) {
      if(e.getSource() == startButton) {
      while(true) {
          obj = new OtherClass();
          obj.doJob();
      }
      else if(e.getSource() == stopButton) {
      obj.stopLoop();
      }
  }
  
  public class OtherClass  {
      private boolean isStopped = false;
      public OtherClass() {
      }
      public void doJob(){
          while(true) {
              //loop...
              if(isStopped) {
                  break;
              }
          }
      }
  </code></pre>