Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8468771
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T16:01:52+00:00 2026-06-10T16:01:52+00:00

Trying to write a timer to do a count down (like a rocket launch:

  • 0

Trying to write a timer to do a count down (like a rocket launch: 3-2-1-Go). What I have seems only to execute once. I need it to repeatedly (almost recursively) execute until the value reaches 0.

As you will see, I have various println statements to follow the progress of this. Here is my output:

in Coundown constructor

in ActionListener

counting down

3

What is wrong is that I am missing the following outputs:

2

1

Go

which indicates to me that this timer is not actually counting down. It seems to be waiting for one second and then terminating.

How can I get this to call itself until the timer reaches zero? Thank you!

public class StopWatch {

    JFrameMath myTest;
    int seconds;

    /* Constructor */
    public StopWatch(JFrameMath thisTest, int sec) {
        myTest = thisTest;
        seconds = sec;

        myTest.hideTestButtons(true);
        Countdown display = new Countdown(myTest);
    }
}

class Countdown extends JFrame implements ActionListener {

    private Timer myTimer = new Timer(250, this);
    JFrameMath myTest;

    public Countdown(JFrameMath thisTest) {

        System.out.println("in Coundown constructor");  

        myTimer.setInitialDelay(1150);
        myTest = thisTest;
        myTimer.start();
    }

    @Override
    public void actionPerformed(ActionEvent e) {

        System.out.println("in ActionListener");      
        int countSeconds = 3;

        if(countSeconds == 0) {
            myTest.showTimeRemaining("Go");
            myTimer.stop();
            System.out.println("done");
        } else {
            System.out.println("counting down");
            myTest.showTimeRemaining(""+countSeconds);
            countSeconds--;
        }

        myTimer.stop();
        myTest.hideTestButtons(false);
    }
}

public void showTimeRemaining(JFrameMath thisTest, String numSec) {
  System.out.println(numSec);
    lblCountdown.setText(numSec);
    thisTest.pack();
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T16:01:53+00:00Added an answer on June 10, 2026 at 4:01 pm

    Remove myTimer.stop() from the end of actionPerformed. That is what’s preventing it from triggering subsequent events. The only place where you want to call stop is inside if (countSeconds == 0).

    Also, I don’t know if it’s a typo or a test, but you need to remove the line int countSeconds = 3; from actionPerformed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I trying to write a PowerShell script (learning at the same time). I have
I'm trying to write a small application and have come across a compile time
I have three fields, namely Number1 Number2 Time I am trying to write a
I am trying to write a regular expression that will count the number of
I am trying to write a query that returns the count of items whose
I'm trying to write code of timer countdown with javascript, sql , c# ,
I have a timer that counts down. I want the displayed format to be
I'm trying to write a JS timer that will be triggered by a user
I have a voting system and I am trying to write a query for
I am trying to write up a bash script to count the number of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.