title: Stop timer with conditional only works first time?
body: <p>I'm writing a "Who Wants to Be a Millionare" game and I have everything set up, it's just a problem with the timer.</p>
  
  <p>The game works like this: if the user gets the question right he/she moves on. If not, the game is over and they can opt to play again.</p>
  
  <p>When the game first runs it's fine and the timer does what it should -- start at 30 seconds and count down, displaying the seconds.</p>
  
  <p>However, when the user clicks the "play again" button, the previous timer continues with the new timer. Like this:</p>
  
  <p>-timerA had 20 seconds left before the user lost (indicated by a).</p>
  
  <p>-timerB begins the next time the game is played (indicated by b).</p>
  
  <p>output: 20a 29b 19a 28b 18a 27b 17a 26b ....... 2a 11b 1a 10b 9b 8b 7b 6b 5b 4b 3b 2b 1b</p>
  
  <p>So here is my timer class called CountDown:</p>
  
  <pre><code>  import java.util.Timer;
    import java.util.TimerTask;
  
    public class CountDown {
  
        static Timer timer;
        public static int seconds = 30;
  
        public CountDown() {
            timer = new Timer();
            timer.schedule(new DisplayCountdown(), 0, 1000);
        }
  
        class DisplayCountdown extends TimerTask {
  
            int seconds = 30;
  
            public void run() {
  
                    if (seconds == 0) {
                        timer.cancel();
                        timer.purge();
                        return;
                    }
  
                if (seconds &gt; 0) {
                    PlayFrame.timer.setText("" + seconds); //jLabel used to display seconds
                    seconds--;
                    if (seconds &lt; 30) {
                        if (PlayFrame.right == true) { //check if question was answered correctly
                            System.out.print("true"); //testing purposes
                            PlayFrame.right = false;
                            PlayFrame.showQuestion();
                            PlayFrame.startTimer();
                            seconds = 0;
                            //break;
                        }
                        else if (PlayFrame.right == false) {
                            //break;
                        }
                    }      
  
                    else if (seconds == 0) { //if time runs out its automatic wrong answer
                        PlayFrame.wrong();
                        //break;
                    }      
  
                    else {
                        PlayFrame.wrong();
                        PlayFrame.timer.setText(null);
                        timer = new Timer();
                        //break;
                    }
                }
                System.out.println(seconds); // for testing purposes only
            }
        }
    }
  </code></pre>
  
  <p>and here is some of my PlayFrame:</p>
  
  <pre><code>  import java.awt.Color;
    import java.util.Timer;
  
    public class PlayFrame extends javax.swing.JFrame {
  
        public static void wrong() {
            //determines which losing frame to show
            if (count &lt;= 2){
                LossLevel0 L0 = new LossLevel0();
                L0.setVisible(true);
            }
            else if (count &gt; 2 &amp;&amp; count &lt;= 6 &amp;&amp; count != 6){
                LossLevel1 L1 = new LossLevel1();
                L1.setVisible(true);
            }
            else {
                LossLevel1 L1 = new LossLevel1();
                L1.setVisible(true);
            }
            //"supposed" to stop the timer
            CountDown.timer.cancel();
            CountDown.timer.purge();
        }
  
        public static void startTimer() {
            //creates new CountDown object and timer, also resets seconds
            CountDown countdown = new CountDown();
            CountDown.timer = new Timer();
            CountDown.seconds = 30;
        }
  </code></pre>
  
  <p>I think the trouble may be in when I restart the game. The only code that is in there is I reset all of my variables back to its original state before the game started. Like so:</p>
  
  <pre><code>    // Reset Everything
      PlayFrame.count = 0;
      PlayFrame.answer = new String();
      PlayFrame.count = 0;
      PlayFrame.right = false;
      PlayFrame.winnings = 0;
      CountDown.seconds = 30;
      CountDown.timer = new Timer();
      CountDown.timer.cancel();
      CountDown.timer.purge();
  </code></pre>
  
  <p>Please help, and if you need further information just ask!</p>