Results 1 to 4 of 4
Thread: Trouble with Thread.sleep
- 05-10-2012, 05:40 AM #1
Member
- Join Date
- May 2010
- Posts
- 45
- Rep Power
- 0
Trouble with Thread.sleep
I have some code that I am having trouble with. I want it to simply display the text "ONE", pause 3 seconds, then display "TWO". What is happening is it pauses 3 seconds then displays "TWO", without displaying "ONE". I was having this problem in a program I am running so I made this simplified example and it is still happening.
I just tried it and this is only happening when I use init(), but when I use run() it works. Is there a way to get it to work with init()?
Java Code:import acm.graphics.*; import acm.program.*; public class Testing extends GraphicsProgram { public void init() { GLabel label = new GLabel("ONE"); label.setLocation(100,100); add(label); try { Thread.sleep(3000); } catch(InterruptedException e) { } label.setLabel("TWO"); } }
- 05-10-2012, 09:00 AM #2
Re: Trouble with Thread.sleep
I haven't a clue about the GraphicsProgram class that you extend, but if it's anything like Swing then you need to go through this Lesson: Concurrency in Swing (The Java™ Tutorials > Creating a GUI With JFC/Swing)
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 05-10-2012, 09:13 AM #3
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,606
- Blog Entries
- 7
- Rep Power
- 17
Re: Trouble with Thread.sleep
When people rob a bank they get a penalty; when banks rob people they get a bonus.
- 05-16-2012, 08:45 PM #4
Similar Threads
-
Difference between Thread.yield() and Thread.sleep() methods
By Nageswara Rao Mothukuri in forum New To JavaReplies: 12Last Post: 07-30-2010, 05:37 PM -
how to reduce the thread sleep time and wake up the thread
By baktha.thalapathy in forum Threads and SynchronizationReplies: 2Last Post: 06-24-2010, 07:36 PM -
thread.sleep
By jc5 in forum CLDC and MIDPReplies: 0Last Post: 09-02-2009, 11:51 PM -
Sleep in thread
By jithan in forum New To JavaReplies: 1Last Post: 08-27-2008, 02:27 PM -
How to use the sleep and thread?
By jiuhu in forum Java AppletsReplies: 4Last Post: 08-07-2007, 02:56 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks