title: How to stop a java swing timer
body: <p>This application has 2 threads the one shown here calls a method that pauses an auto clicker method every 4 seconds(just for ease) to do some mouse movement. I want it to stop the timer when you click the gui stop button.
  Right now when you hit stop and then start again it then has two timers that will execute the code; and so on.</p>
  
  <p>Action Listener Stuff.</p>
  
  <pre><code>class MyButtonListener implements ActionListener {
      @Override
      public void actionPerformed(ActionEvent e) {
          if (e.getSource().equals(view.getBtnStart()))
          {
              autoClick.unTerminate();
              bool = true;
              getInfo();
          }
          if (e.getSource().equals(view.getBtnExit()))
          { 
              System.exit(0);
          }
          if (e.getSource().equals(view.getBtnStop()))
          {
              bool = false;
              autoClick.terminate();
          }
      }//end of actionPerformed
  }//end of inner class
  </code></pre>
  
  <p>Thread</p>
  
  <pre><code>Thread t2 = new Thread(new Runnable() {
                      @Override
                      public void run() {
                          Timer timer = new Timer(4000, new ActionListener() {//301000 5minutes and 1second
                              @Override
                              public void actionPerformed(ActionEvent evt) {
                                  autoClick.timeOverload();
                              }                                
                          });
                          //if (!bool){timer.stop();}
                          timer.setRepeats(true); //false only repeates once
                          timer.start();
                      }
                      });//end of t2
  </code></pre>
  
  <p>It calls the timeOverload method repeatedly.</p>
  
  <p>Thanks for your time and helping a newbie out :).</p>