Results 1 to 4 of 4
Thread: Working with threads.
- 04-06-2011, 05:50 AM #1
Member
- Join Date
- Apr 2011
- Posts
- 8
- Rep Power
- 0
Working with threads.
Okay, I'm trying to set a cool little animation.
Basically, when the user presses down space, a boolean "req" is set to true, and a thread is started. The run() method is in the same class. The run method consists of a while loop which runs as req == true. When the user released the space bar, req is set to false, which I hoped would end the while loop, but instead it continues to loop. I used some System.out.println(req) tests along the way, and found that the thread thinks that req is set to true the entire time, even after releasing the space bar. How can I make it so that the while loop stops running after the space bar is released. (And yes, there has to be a while loop).
- 04-06-2011, 06:03 AM #2
Member
- Join Date
- Apr 2011
- Posts
- 8
- Rep Power
- 0
I... just figured out.... what happened.... I think I have a concussion... because I face palmed so hard.... I honestly, don't want to say what I did wrong, but trust me, it was stupid. But yeah, it works flawlessly now!
- 04-06-2011, 06:09 AM #3
Member
- Join Date
- Mar 2011
- Posts
- 26
- Rep Power
- 0
I think threads in java have their own scopes and that's why you get this error. Try checking the req variable directly from the superclass like:
I think this may work...Java Code:while(VariableClass.getReq()){ // Record the animation }
- 04-06-2011, 06:24 AM #4
Member
- Join Date
- Apr 2011
- Posts
- 8
- Rep Power
- 0
Similar Threads
-
\n not working in GUI (working code, but \n isn't working)
By cc11rocks in forum New To JavaReplies: 2Last Post: 01-04-2011, 04:30 AM -
Threads
By Tanuck in forum New To JavaReplies: 5Last Post: 09-21-2010, 02:44 AM -
GUI and Threads
By rp181 in forum Threads and SynchronizationReplies: 1Last Post: 10-10-2009, 08:39 PM -
Java mail problem(working in intranet,but not working in iternet)
By sundarjothi in forum Advanced JavaReplies: 8Last Post: 05-28-2008, 07:00 AM -
Threads
By one198 in forum Threads and SynchronizationReplies: 1Last Post: 11-20-2007, 06:15 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks