954,549 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Time delay

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

tdizzle342
Newbie Poster
19 posts since Oct 2005
Reputation Points: 10
Solved Threads: 0
 

Thread.sleep() comes to mind.

jwenting
duckman
Team Colleague
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
 

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

5up3rJ
Newbie Poster
3 posts since Jan 2006
Reputation Points: 10
Solved Threads: 0
 

Sweet!! Thanks man works perfectly.

tdizzle342
Newbie Poster
19 posts since Oct 2005
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You