0

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?

3
Contributors
3
Replies
4
Views
8 Years
Discussion Span
Last Post by eng_mary
0

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.

0

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?

0

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.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.