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.


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){

} }


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); }


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(); } }

Items you will need

About the Author

G.S. Jackson specializes in topics related to literature, computers and technology. He holds a Bachelor of Arts in English and computer science from Southern Illinois University Edwardsville.