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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:36:46+00:00 2026-06-17T12:36:46+00:00

I am making a matching game in java and it is going pretty well.

  • 0

I am making a matching game in java and it is going pretty well. The problem is that when I click on a second card, if they are not the same the cards turn back, but it never shows you what the second card is. I was thinking about delaying the program after the two cards are shown, but it won’t work. It only shows the first card, delays the program and then does what it did in the first place. It won’t show the second picture. I’ve tried wait() and Thread.sleep(1000), but none of them will produce the effect I want.

// code above where it finds the first card and shows it
y.setIcon(FindTheCard(es2,'c')); //showing the second card
            try{Thread.sleep(3000L); // delaying
            }catch(Exception e){}

I am pretty new to threads, so I guess the first thing that runs is the thread and then the rest of the code, which is not what I want. I want y.setIcon(..) to be executed and then to have a little delay before the rest of the code runs.
Everything about my code works perfectly, so I suppose it’s just my lack of knowledge. All I need is the delay.

However, I have also tried this code:

public class testing {

    public static void main(String[] args) {
        System.out.println("Do this stuff");
        try { Thread.sleep(500); }
        catch ( Exception e ) { }
        System.out.println("Now do everything after this");

    }

}

and it works. There is a little delay between the two sentences. How can I do the same with my cards – which are actually buttons. I also removed the code where it turns the cards back after they’re shown and the cards do stay the same. So there’s no problem regarding the second card or the icon.

  • 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-17T12:36:47+00:00Added an answer on June 17, 2026 at 12:36 pm

    As mentioned, Swing is single threaded. There is a single thread, called the Event Dispatch Thread that performs all rendering and is where all Swing events are handled (your ActionListeners and other sorts of listeners all run on that thread). It is important not to perform any long running processes (server calls, disk I/O, Thread.wait()s) on that thread, because it will cause the GUI to hang. Look at this tutorial for more detail and examples.

    For your case, you may also want to look at Swing Timers, as they seem purpose built for your desired effect.

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

Sidebar

Related Questions

I'm making a date matching regex, and it's all going pretty well, I've got
Making websites that appear correctly in IE is a big problem. Is there any
I've a problem in making a PERL program for matching the words in two
I'm making a turn based game, and trying to construct the matching function, when
I'm making a tic-tac-toe game. How would I change the following code so that
I've been making a game and its been going OK, but I've made it
I'm working on a problem that's making my brain melt although I don't think
I'm making a card game for the iPad (Panic, Nervous Breakdown,Stress). To win you
I am making a login page that checks for matching values in a database
Making an adobe flex ui in which data that is calculated must use proprietary

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.