You can use:
Thread.sleep(2000);
or
java.util.concurrent.TimeUnit.SECONDS.sleep(2);
Please note that both of these methods throw InterruptedException
, which is a checked Exception, So you will have to catch that or declare in the method.
Edit: After Catching the exception, your code will look like this:
if (doAllFaceUpCardsMatch == false) { try { Thread.sleep(2000); } catch (InterruptedException e) { e.printStackTrace(); } concentration.flipAllCardsFaceDown(); } else { concentration.makeAllFaceUpCardsInvisible(); }
Since you are new, I would recommend learning how to do exception handling once you are little bit comfortable with java.
Related Posts:
- How to set a Timer in Java?
- How do I get my Python program to sleep for 50 milliseconds?
- Creating a timer using Lua
- Pause the timer and then continue it
- How to add a “sleep” or “wait” to my Lua Script?
- Make a simple timer in Java
- Adding a timer to my program (javafx)
- How to format strings in Java
- What exactly is Apache Camel?
- What is an instance variable in Java?
- How does the Java ‘for each’ loop work?
- How does the Java ‘for each’ loop work?
- What does “Could not find or load main class” mean?
- How do I create a file and write to it?
- When to use LinkedList over ArrayList in Java?
- Can’t start Eclipse – Java was started but returned exit code=13
- How to convert a char to a String?
- bad operand types for binary operator “&” java
- How can I use pointers in Java?
- How do I generate random integers within a specific range in Java?
- “Exception in thread “main” java.lang.IndexOutOfBoundsException: Index: 0, Size: 0″ with ArrayList?
- Raising a number to a power in Java
- Explanation of ClassCastException in Java
- How do I limit the number of decimals printed for a double?
- Unfortunately MyApp has stopped. How can I solve this?
- exception in thread ‘main’ java.lang.NoClassDefFoundError:
- java.io.FileNotFoundException: the system cannot find the file specified
- How to parse this string in Java?
- How to match “any character” in regular expression?
- Double array initialization in Java
- I want to declare an empty array in java and then I want do update it but the code is not working
- Explain the use of a bit vector for determining if all characters are unique
- java.text.ParseException: Unparseable date
- Convert java.util.Date to String
- How do I do a deep copy of a 2d array in Java?
- Returning an empty array
- Java Security: Illegal key size or default parameters?
- Could not reserve enough space for object heap
- Eclipse: Java was started but returned error code=13
- Why java unknown: import org.apache.commons.codec.binary.Base64;?
- Extracting .jar file with command line
- Java; String replace (using regular expressions)?
- Unable to create requested service [org.hibernate .engine.jdbc.env.spi.JdbcEnvironment]-MySQL
- Why do I get “Exception; must be caught or declared to be thrown” when I try to compile my Java code?
- JRE 1.7 – java version – returns: java/lang/NoClassDefFoundError: java/lang/Object
- Good Java graph algorithm library?
- Integrate Ant builder into Eclipse: Error “Variable references empty selection”
- Convert a byte array to integer in Java and vice versa
- Spring Maven clean error – The requested profile “pom.xml” could not be activated because it does not exist
- Java Class File Editor
- Error Importing SSL certificate : Not an X.509 Certificate
- How do I draw a triangle?
- warning: [options] bootstrap class path not set in conjunction with -source 1.5
- Installing jdk8 on ubuntu- “unable to locate package” update doesn’t fix
- Java – Access is denied java.io.FileNotFoundException
- Static Block in Java
- What does Scanner input = new Scanner(System.in) actually mean?
- RecyclerView onClick
- Java, Shifting Elements in an Array
- error: bad operand types for binary operator ‘&&’
- Exception in thread “main” java.lang.ArithmeticException: / by zero
- Failed to load the JNI shared Library (JDK)
- “com.jcraft.jsch.JSchException: Auth fail” with working passwords
- java.util.NoSuchElementException – Scanner reading user input
- How would I use a while loop to keep requesting user input
- Array Required, but java.lang.String found
- How to save decimal in java
- Eclipse java debugging: source not found
- How to use Comparator in Java to sort
- Adding days to a date in Java
- The C# Shorthand getters and setters
- What’s the reason I can’t create generic array types in Java?
- How to pass an object from one activity to another on Android
- Finding the size of a char array in Java
- Android For loop
- How to draw lines in Java
- Java project in Eclipse: The type java.lang.Object cannot be resolved. It is indirectly referenced from required .class files
- NoClassDefFoundError in Java: com/google/common/base/Function
- Printing a java map Map
– How? - fixing errors on a program to call methods in java
- How to Set the Background Color of a JButton on the Mac OS
- How to easily convert a BufferedReader to a String?
- How can I calculate a time difference in Java?
- Detecting a long press with Android
- How to increase the size of an array in Java?
- Cannot invoke toString() on the primitive type int
- Creating a Calendar using javafx
- How fix Error:java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException:
- Is it okay to throw NullPointerException programmatically?
- Android: how to create Switch case from this?
- Read next word in java
- Convert float to double without losing precision
- Exception in thread “AWT-EventQueue-0” java.lang.OutOfMemoryError: Java heap space
- How do the post increment (i++) and pre increment (++i) operators work in Java?
- Manually throw an exception
- Spring boot: Unable to start embedded Tomcat servlet container
- How does paintComponent work?
- Java GC (Allocation Failure)
- toring and Retrieving ArrayList values from hashmap
- How can I upgrade to Java 1.8 on an Amazon Linux Server?