title: Swing timer not stopping
body: <p>I'm using the swing Timer to make a countdown clock in Netbeans:</p>
  
  <pre><code>public void startTimer() {
  
      System.out.println(right + "value");
      ActionListener listener = new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent event) {
              System.out.println("action");
              timerLabel.setText("" + seconds);
              --seconds;
              System.out.println(seconds);
              if (seconds == -1 &amp;&amp; seconds &lt; 0) {
                  System.out.print("zero");
                  //displayTimer.stop();
                  wrong();
                  dispose();
              }
          }
      };
      displayTimer = new Timer(1000, listener);
      displayTimer.setInitialDelay(100);
      displayTimer.start();
  
      if (right == null) {
          System.out.println("null");
      } else if (right == true) {
          System.out.println("truehere");
          displayTimer.stop();
          right = null;
          seconds = 20;
          displayTimer.setDelay(10000);
          displayTimer.setInitialDelay(100);
          displayTimer.start();
      } else if (right == false) {
          System.out.print("wrong");
          //displayTimer.stop();
          seconds = 20;
      }
  
  
  }
  </code></pre>
  
  <p>I just use System.out.print to test the program, it's not a part of the real program.
  I call the stop() method but the timer continues to count. Also, I create a new timer by <code>displayTimer = new javax.swing.Timer(10000, listener);</code> but it counts twice as fast. Can anyone help?</p>
  
  <p>EDIT:</p>
  
  <p>Here is my timer (sort of SSCCE):</p>
  
  <pre><code>import java.awt.*;
  import java.awt.event.ActionEvent;
  import java.awt.event.ActionListener;
  import java.util.Scanner;
  
  import javax.swing.*;
  
  public class JavaApplication8 {
   public static void startTimer() {
      ActionListener listener = new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent event) {
              int seconds = 20;
              seconds--;
              System.out.println(seconds);
  
              if (seconds == -1 &amp;&amp; seconds &lt; 0) {
                  System.out.print("zero");
              }
          }
      };
      Timer displayTimer = new Timer(1000, listener);
      displayTimer.setInitialDelay(100);
      displayTimer.start();
   }
  
  public static void main(String[] args) {
      System.out.println("Type win to win!");
  
      startTimer();
  
      String read;
      Boolean right;
      int seconds;
  
      Scanner scanIn = new Scanner(System.in);
      read = scanIn.nextLine();
  
      if (read.equals("win")){
          right = true;
      }
      else{
          right = false;
      }
  
      if (right == true) {
          System.out.println("correct");
          //displayTimer.stop();
          right = null;
          seconds = 20;
          //displayTimer.setDelay(10000);
          //displayTimer.setInitialDelay(100);
          //displayTimer.start();
      } else if (right == false) {
          System.out.print("incorrect");
          //displayTimer.stop();
          seconds = 20;
          right = null;
      }
  }
  }
  </code></pre>
  
  <p>it doesn't work right in that the seconds don't show up, but it does show 20 times which is what I want. This is just in its own application, in my real program it is easier to see the problem.</p>
  
  <p>I've noticed that the first time the game runs it works fine. Then I click play again (resets the whole game) and it goes twice as fast. Maybe I'm not resetting something correctly? Here is my reset code:</p>
  
  <pre><code>// Reset Everything
      PlayFrame.seconds = 20;
      PlayFrame.winnings = 0;
      PlayFrame.right = false;
      //PlayFrame.displayTimer.stop();
      PlayFrame.questionLabel.setText(null);
      PlayFrame.count = 0;
      WelcomeFrame WFrame = new WelcomeFrame();
      WFrame.setVisible(true);
      setVisible(false);                             
      PlayFrame P = new PlayFrame();
      P.dispose();
  
      if (PlayFrame.seconds == -1 &amp;&amp; PlayFrame.seconds &lt; 0){
          PlayFrame.displayTimer.stop();
      }
  }
  </code></pre>