Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

having trouble stopping and starting a thread  RSS feed

 
Michael Bruesch
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm writing a miniature golf game using double buffering. When the "ball" travels over the "hole", I set the thread to null and print "Congratulations!" on the screen. I want to make it so the user can click on the screen and try again (restart the thread). In my mousePressed method I set the Thread runner = new Thread (this); and then runner.start ();. This seems buggy...if the user clicks on the screen if the ball doesn't make it into the hole, the thread seems to go faster. Multiple clicking on the screen will make the ball go really fast. It can go so fast that it will shoot over the hole and not register that it was supposed to go in. Is there a way where you can just make the current thread stop until you tell it to restart?..instead of setting one thread to null then starting a new one. by the way, I'm implementing the Runnable interface...should I extend the Thread class? Will that give me more options?
Thanks!
------------------
Michael J Bruesch
Codito, ergo sum...
I code, therefore I am.
My Java Games, I'm quite proud
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why don't we move this over to the Threads forum for starters.
 
Jim Baiter
Ranch Hand
Posts: 532
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There was a bunch of discussion about this on another thread. The only way I know of is to provide some exit condition from your run method using a member variable.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!