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 8966241
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:59:04+00:00 2026-06-15T16:59:04+00:00

I need a timer implemented in my application, which will do a countdown from

  • 0

I need a timer implemented in my application, which will do a countdown from 10 sec – 0 sec.
and, display the countdown in a JLabel.

Here’s my implementation;

...
Timer t = new Timer(1000, new List());
        t.start();

}

class List implements ActionListener{

    @Override
    public void actionPerformed(ActionEvent e) {
        int sec = 0;
        label.setText(""+sec);
        // Do a if- condition check to see if the clock has reached to, and then stop

    }

}

I was expecting the JLabel to start counting from 0 – 10 and then stop. But it doesn’t. The JLabel set the value 0 and it doesn’t get incremented.

UPDATE 1

    t = new Timer(1000, new Listner());
    t.start();


}

class Listner implements ActionListener{
    private int counter = 0;
    @Override
    public void actionPerformed(ActionEvent e) {
        lable.setText(""+ (counter++));

        if (counter == 10)
              t.removeActionListener(this);

    }

}
  • 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-15T16:59:06+00:00Added an answer on June 15, 2026 at 4:59 pm

    You are not storing nor incrementing secs anywhere so I don’t see how it should get updated, try with

    Timer timer;
    
    void start() {
      timer = new Timer(1000,new List());
    }
    
    class List implements ActionListener {
        private counter = 0;
        @Override
        public void actionPerformed(ActionEvent e) {
            label.setText(""+counter++);
    
            if (counter == 10)
              timer.removeActionListener(this);
        }
    }
    

    Mind that you need to store a reference to the timer somewhere to be able to remove the listener from it once countdown finished.

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

Sidebar

Related Questions

I have an application in Zend where I need to implement system which will
I need a timer which will send a message for its' handler. I've made
I am making a contest platform ..For it I need a countdown timer ..The
I've got a legacy application which is implemented in a number of Excel workbooks.
I have an application which needs to display around 50 images saved in the
Here's the scenario: I have a multi threaded java web application which is running
I need to draw 2d line chart on a MFC view which will be
I am developing an application for the Android platform which contains 1000+ image filters
From a logical point of view an application may need dozens or hundreds of
i need a timer that works like this : imagine somebody have a limit

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.