Hi , i was just wondering how you would produce a time delay in java. Bascically all im trying to do is draw a circle in a bunch of random places. Just draw circles way to fast. Here my code

import java.awt.*;
import hsa.Console;


public class Delay
{
static Console c;


public static void main (String[] args)
{
c = new Console ();
design();
}
static public void design () // randomly draws circles over HSA Console
{
int up = 0;
int x ;
int y;
int height;
int width ;
for (int counter = 0 ;; counter ++ ) // need to waste time between each
{                                   // for statement repetion
x = (int) (Math.random () * 500);
y = (int) (Math.random () * 500);
height = (int) (Math.random () * 100 );
width = (int) (Math.random () * 100 );
c.setColor (Color.red);
c.drawOval (x,y,height,width);
delay (10000);
}
}
public void delay (int howLong) // delay function to waste time
{
for (int i = 1 ; i <= howLong ; i++)
{
double garbage = Math.PI * Math.PI;
}
}
}

Recommended Answers

All 3 Replies

Thread.sleep() comes to mind.

try
{
Thread.sleep(1000); // do nothing for 1000 miliseconds (1 second)
}
catch(InterruptedException e)
{
e.printStackTrace();
}

Sweet!! Thanks man works perfectly.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.