0

I'm currently making the skeleton of a game inside of intelij because I can't do graphics processing yet. The current situation is that I need dialogue so there for I need to use print functions and pauses between them.

public class Intelijence {
    public static void main(String[] args) {
        System.out.println("dfdfddd");
        ?
        System.out.println("dfdfddd");
    }
}

So I know some Ideas Like the sleep and wait functions but I'm not sure I am entering them in wrong or if they are just for another language (BTW it's in java)

Woodchuck
  • 3,869
  • 2
  • 39
  • 70

2 Answers2

2

You can use Java's TimeUnit class. Specifically its sleep method.

For example, this would pause for 10 seconds:

TimeUnit.SECONDS.sleep(10);

And this would pause for 5 minutes:

TimeUnit.MINUTES.sleep(5);

Just add this line, adjusted for the time period you wish to pause, between your print statements.

Woodchuck
  • 3,869
  • 2
  • 39
  • 70
1

You can use Thread.sleep(milliseconds) method to make calling thread go into a sleep state until the timeout (milliseconds) expires. It it also important to note that Thread.sleep method throws an InterruptedException, so your program will need to handle it accordingly -

You can do something like this -

public class Intelijence  {
    public static void main(String[] args) throws InterruptedException {
        System.out.println("dfdfddd");
        Thread.sleep(5000);
        System.out.println("dfdfddd");
    }
}

This will make your main thread to sleep after 1st print statement and will print 2nd print statement after 5 seconds.

You can read more about this here.

Hope this helps!

Tanuj
  • 2,032
  • 10
  • 18