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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T15:32:48+00:00 2026-06-15T15:32:48+00:00

Basically, I have this game where once guesses the correct answer it starts a

  • 0

Basically, I have this game where once guesses the correct answer it starts a new game with a new word. I want to display Correct! but after three seconds, change it to a empty string. How do I do that?

My attempt:

if (anagram.isCorrect(userInput.getText()))
    {

        anagram = new Anagram();
        answer.setText("CORRECT!");
        word.setText(anagram.getRandomScrambledWord());
        this.repaint();
        try
        {
        Thread.currentThread().sleep(3000);
        }
        catch (Exception e)
        {
        }
        answer.setText("");

    } else
    {
        answer.setForeground(Color.pink);
        answer.setText("INCORRECT!");
    }

Edit:

My solution:

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt)
    {
        // TODO add your handling code here:
    if (anagram.isCorrect(userInput.getText()))
    {
        answer.setText("CORRECT!");

        ActionListener taskPerformer = new ActionListener()
    {
    public void actionPerformed(ActionEvent evt)
    {
        anagram = new Anagram();
        word.setText(anagram.getRandomScrambledWord());
        answer.setText("");
        userInput.setText("");
    }
    };
    Timer timer = new Timer(3000, taskPerformer);
    timer.setRepeats(false);
    timer.start();
    } else
    {
        answer.setForeground(Color.pink);
        answer.setText("INCORRECT!");
    }
    }

I am not sure, but I hope that I am following MadProgrammer’s advice and not blocking the event itself, but the new thread. I will look up Java Timer also.

  • 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-15T15:32:49+00:00Added an answer on June 15, 2026 at 3:32 pm

    Swing is an event driven environment. While you block the Event Dispatching Thread, no new events can be processed.

    You should never block the EDT with any time consuming process (such as I/O, loops or Thread#sleep for example).

    You might like to have a read through The Event Dispatch Thread for more information.

    Instead, you should use a javax.swing.Timer. It will trigger a ActionListener after a given delay.

    The benefit of which is that the actionPerformed method is executed with the context of the Event Dispatching Thread.

    Check out this or this or this or this for an examples

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

Sidebar

Related Questions

Ok, so basically I have this part of the .htaccess partly working, but not
Basically I'm working on a new game and have decided to come up with
I have this error that is keeping me from moving forward. I basically have
Basically I have this string for example $str = 'По, своей 12' I need
Basically I have this string $str=word1 word2 word3; I need array( 'word1', 'word2', 'word3'
So basically I have this giant regular expression pattern, and somewhere in the middle
I have (basically) this code - <script type=text/javascript language=javascript> $(document).ready(function() { $(#loadDiv).load(mypage.html, function(){ alert($(#someText).text())
I have this type which is basically a struct { int x,y,z; } that
I have this script which basically toggles a bgColor class on and off so
I have this grand idea to basically employ some brute force attack to test/verify

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.