This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Time.Delay  RSS feed

 
Shane Lilly
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do I implement this in a java file...
Im in the middle of a for loop and I want a small delay before I do the next thing in the for loop.
When I include Time.Delay(100);
It gives me an error 'Cannot resolve symbol'.
Is there a java class that I need to import in order to use this, or am I going the wrong way about it?
Thanks
 
Kim Kantola
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you using the java.sql.Time class, or is the "Time" class that you refer to one of your own?
Looking here:
Java 2 Platform Doc
I don't see any reference to a delay method in the Time class.
 
brad balmer
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try using:
try {
Thread.sleep(x);
}catch (InterruptedException) {}
Where x are milliseconds
 
Adam Brown
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree with Brad. Putting your thread to sleep is an easy way to put a time delay in a process. The only thing is that you need put your thread to sleep within a try/catch block. Here's an example that prints out 10 numbers with a five second delay between each display:
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!