Results 1 to 5 of 5
- 08-07-2011, 09:21 AM #1
Member
- Join Date
- Aug 2011
- Posts
- 2
- Rep Power
- 0
how to refresh frame during thread
hey everyone,
basically what im doing is im running a thread which implements a while statement. within this while statement an action is performed and then the thread sleeps for a short period of time before continuing. everything works fine except the frame doesnt refresh until the thread is complete, does anyone have any ideas on how i can update it everytime it sleeps?
here is the code of the thread in case it helps:
thanks in advance, cobJava Code:public class autoSlow extends Thread { public void run() { while(ballResult!=5) { ball.doClick(); try { this.sleep(600); } catch (InterruptedException e) {} } } }Last edited by sunde887; 08-07-2011 at 09:40 AM. Reason: Added code tags, [code]...[/code]
- 08-07-2011, 10:14 AM #2
Go through the tutorial on Concurrency in Swing.
also, the code snippet you posted doesn't reveal the real problem. Additionally, read the documentation for Runnable:
dbIn most cases, the Runnable interface should be used if you are only planning to override the run() method and no other Thread methods. This is important because classes should not be subclassed unless the programmer intends on modifying or enhancing the fundamental behavior of the class.
- 08-08-2011, 11:37 AM #3
Member
- Join Date
- Aug 2011
- Posts
- 2
- Rep Power
- 0
hmmmmm i went through the tutorial and a swing worker thread seems to be what i want, but i have no idea what to publish seeing as my repaint methods aren't threads, they're methods. any idea of what i could write instead of what ive got above that performs the same method but repaints after each sleep?
- 08-08-2011, 01:41 PM #4
All code executes on a thread. The Thread class allows you to create additional threads as needed.my repaint methods aren't threads,
If you have changed the GUI and what the paintComponent method called to re draw something, call the repaint() method.
- 08-08-2011, 03:09 PM #5
Similar Threads
-
How to set Jpanel in the center of frame when Increase the size of frame
By justbeller in forum AWT / SwingReplies: 4Last Post: 01-18-2011, 08:22 AM -
how to open one frame to another frame
By tukadiya in forum AWT / SwingReplies: 1Last Post: 12-20-2010, 08:27 PM -
Java slave Frame access to its owner main frame problem
By cagdaseckin in forum New To JavaReplies: 0Last Post: 12-10-2010, 10:40 AM -
Returning focus to a frame after hiding another frame
By fletcher in forum AWT / SwingReplies: 7Last Post: 11-02-2009, 06:31 PM -
Inside a Timer thread loop,how to refresh a JTable in swing
By neha_negi in forum Threads and SynchronizationReplies: 3Last Post: 09-04-2009, 01:45 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks