aspose file tools
The moose likes Threads and Synchronization and the fly likes having trouble stopping and starting a thread Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Reply Bookmark "having trouble stopping and starting a thread" Watch "having trouble stopping and starting a thread" New topic
Author

having trouble stopping and starting a thread

Michael Bruesch
Ranch Hand

Joined: Sep 23, 2001
Posts: 158
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


Michael J Bruesch<br /><i>I code, therefore I am.</i>
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
Why don't we move this over to the Threads forum for starters.


"JavaRanch, where the deer and the Certified play" - David O'Meara
Jim Baiter
Ranch Hand

Joined: Jan 05, 2001
Posts: 532
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.
 
I agree. Here's the link: jrebel
 
subject: having trouble stopping and starting a thread
 
Similar Threads
Physics
bouncy ball applet image problem
Beginner question - Key events
Arjun Atwal winning on the US PGA Tour
Pong problems