Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Java Game thread.sleep()  RSS feed

 
siddharth sekhar
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello , i am learning java game development by myself and have some questions
, first of all i used thread.sleep(); to animate my object , but in a forum i was said to use swing timer , so how to use swing timer instead of thread.sleep() .

 
Paul Clapham
Sheriff
Posts: 22502
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would recommend swing timer tutorial as your web search terms. Or did you try that already? If so, it's best to let us know what you found and what specific problems you found when reading it.
 
siddharth sekhar
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:I would recommend swing timer tutorial as your web search terms. Or did you try that already? If so, it's best to let us know what you found and what specific problems you found when reading it.


i was using this code



now i an using this , but it is not working



there is no delay in my output
 
Paul Clapham
Sheriff
Posts: 22502
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, yeah. Your Timer doesn't do anything. Which tutorial did you read which recommended that idea?
 
Campbell Ritchie
Marshal
Posts: 55745
163
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul C is right. You should avoid Thread#sleep in Swing applications. That puts the current Thread to sleep; it may do so before the display has been repainted. If you keep the Thread sleeping, you may never see any changes to the GUI at all. I would suggest you look at this tutorial.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!