How to Get a Delay Effect in Java Eclipse

By G.S. Jackson

The Eclipse Java Interactive Development Environment (IDE) allows programmers to easily deploy Java applications through its included code completion functions, built-in debugger, and error checking capabilities. Outside of this, anything that you can do with a Java library can be done in Eclipse. For example, if you wanted to create a delay effect in an Eclipse program, you would use Java's "Thread" library, and its included "sleep" method.

Step 1

Create your Eclipse project. In the main class, begin the main function as follows:

import java.lang.Thread;

class TestProject{

public static void main(String[] args){

} }

Step 2

Set up the delay loop. This contains the call to the Thread libraries "sleep" method. For each iteration, the delay time will increase by one second as it is multiplied by the increasing "x" variable:

for(int x = 0; x <= 10; x++){ Thread.sleep(1000 * x); }

Step 3

Wrap the sleep method call in a "try...catch" block. The "InterruptedException" object in the try...catch block activates when another thread interrupts the current thread while the sleep method is active. This can help you ensure that all threads in a program shutdown cleanly.

for(int x = 0; x <= 10; x++){ try { Thread.sleep(1000 * x); } catch(InterruptedException e){ Thread.currentThread().interrupt(); } }