/***********************
This demonstrates how to use Thread.sleep
to delay a program.
Notice that .sleep can throw an InterruptedException
-
so try and catch are needed.
Also notice that the wait method must receive
a double, and so 1 second must be written 1.0.
**************************/
import java.awt.*;
public class DelayExample extends EasyApp
{
public static void main(String[] args)
{
System.out.println("Hi");
for (int i = 0; i < 10; i++)
{
System.out.println(i);
System.out.println("Wait:");
wait(1.0);
}
System.out.println("Bye");
}
static void wait(double seconds)
{
try
{
Thread.sleep((long)(1000*seconds)); // 1000 milliseconds = 1 second
}
catch (InterruptedException ie)
{ System.out.println(ie.getMessage()); }
}
}