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

  • Home
  • SEARCH
  • 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 6750687
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:50:17+00:00 2026-05-26T12:50:17+00:00

After advice from another thread, I’ve been playing with the timer class without much

  • 0

After advice from another thread, I’ve been playing with the timer class without much joy. Heres my code:

 public void buttonImageReveal(ActionEvent e){

        Timer gameTimer = new Timer(100, new ActionListener() {

            public void actionPerformed(ActionEvent e) {

              repaint();
            }
          });

        String temp = e.getActionCommand();

        switch(temp){
                        case "1":
                            System.out.println("case1");                            
                            ((JButton)e.getSource()).setIcon(one);
                            gameTimer.start();
                            ((JButton)e.getSource()).setIcon(null);
                            break;

All I want is a 1 second gap between the image one been shown as the icon then that been removed. Only to happen once when the button is click. At the moment I just get a blank button when pressed?

TIA

Edit:

     public void actionPerformed(ActionEvent e) {
          System.out.println(e);
          lastImage();

        }

      });

public void buttonImageReveal(ActionEvent e){ 

        String temp = e.getActionCommand();

        switch(temp){
                        case "1":                       
                            ((JButton)e.getSource()).setIcon(one); 
                            lastBtn = ((JButton)e.getSource()); 
                            gameTimer.start();

                            break;

It now doing what it should, but the timer keeps going and going, what do you do to once your finished and want it to stop?!

  • 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-05-26T12:50:17+00:00Added an answer on May 26, 2026 at 12:50 pm

    You set the icon, start a timer and then immediately remove the icon. The start() method from the timer is almost immediately going to return and the timer will perform its task asynchronously. You’ll need to do the icon removing in the actionPerformed method.

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

Sidebar

Related Questions

I am after so advice really. I have been thinking about a client server
After following the great advice given in a thread about service beans I have
How can I navigate from a JSF page to another after I did double
It's been a while since I programmed in C++, and after coming from python,
after some advice regarding a problem i am getting using a linux based piece
Summary I am after some advice on the easiest way to analyze simple data
After following the advice in this question successfully, I added a couple additional lines
I'm after some design advice. I'm working on an application with a fellow developer.
I'm after a bit of advice on how to handle a multi tenant site
I'm a newbie to Unit Testing and I'm after some best practice advice. I'm

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.