I'm new to Java and making a small game for practice.
if (doAllFaceUpCardsMatch == false) {
//run pause here//
concentration.flipAllCardsFaceDown();
} else {
concentration.makeAllFaceUpCardsInvisible();
}
I want to pause the game for two seconds here before it does
concentration.flipAllCardsFaceDown();
How would I go about pausing it?
Thread.sleep
would be the obvious choice, however, if you're using a GUI like Swing or JavaFX, you shouldn't do this from within the context of their dispatching threads, that would be really, really bad. Most UI frameworks will have their own defined mechanisms for doing this, but we don't have that information – BuiltInterruptedException
, or declare it to be thrown. – Zlatousttrue
andfalse
. – Stuckey