Hi every one.

suppose i have Car class:

public class Car{
  int id;
  int speed;

  public void move(){
   ...
  }
  .....
}

that have to run in Race class:

public class Race{
  Car[] cars;
  ....
  public void runRace(){
     ..
     for (int i=0; i<cars.length; i++)
     {
          cars[i].move();
          //here is my problem
     }
}

i need to simulate cars movement in runRace() using time intervals, and the question is:

Is there any java statment that let me wait some time in //here is my problem place without using thread?

You could use the Java class Timer. Or you could do something inane like

int i = 0;
while(i < whatever) i++;

And this while loop would take a certain amount of time to complete, so there would be your pause.

I think you can still use Thread.sleep(int milliseconds); to pause execution of the program. Even if you don't extend Thread or implement Runnable. I think i have done that before. Do you want to avoid using Threads, or just the Thread methods?

I think you can still use Thread.sleep(int milliseconds); to pause execution of the program.

thank you very much that exactly what i want: one java statement to pause run for a while.

is there any Timer class similar method that do the same without using Thread at all.

This question has already been answered. Start a new discussion instead.