Home arrow static arrow Java Programming [Archive] - GUI design question
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - GUI design question
This topic has 6 replies on 1 page.

Posts:5
Registered: 7/6/04
GUI design question  
Aug 9, 2004 6:39 AM



 
I'm looking to implement a GUI (using SWT) where the user presses a button that launches an activity that takes 0-30 seconds to complete, then relaunches every X seconds in perpetuity or until the use presses a button to stop the process.

Looked at util.timer and Swing.timer, but the fact that I'm using SWT seems to preclude the use of those, since I need to update the GUI after every iteration.

Am I missing something or is there not a way to accomplish this?
 

Posts:14,142
Registered: 99-04-02
Re: GUI design question  
Aug 9, 2004 7:03 AM (reply 1 of 6)



 
If SWT doesn't include a timer class, then I don't see why you couldn't use util.Timer. It's nothing to do with Swing.
 

Posts:458
Registered: 7/1/03
Re: GUI design question  
Aug 9, 2004 8:34 AM (reply 2 of 6)



 
Use java.util.TimerTask
 

Posts:5
Registered: 7/6/04
Re: GUI design question  
Aug 9, 2004 9:27 AM (reply 3 of 6)



 
SWT apparently doesn't have a timer(!!??). util.Timer almost works, but I haven't been able to find a way to access the GUI from the run() method of the timertask to update at the end of each iteration.
 

Posts:14,142
Registered: 99-04-02
Re: GUI design question  
Aug 9, 2004 10:55 AM (reply 4 of 6)



 
give the timer a reference to the GUI object you want to update and call the methods.
 

Posts:5
Registered: 7/6/04
Re: GUI design question  
Aug 9, 2004 1:02 PM (reply 5 of 6)



 
If only it were that simple. Apparently the UI runs in a special thread that can't be accessed by other threads directly. After a lot of digging I found some SWT snippets where some Display methods (syncExec, asyncExec) enable updating UI thread. Working so far. What a pain. Thanks.
 

Posts:458
Registered: 7/1/03
Re: GUI design question  
Aug 9, 2004 1:07 PM (reply 6 of 6)



 
If only it were that simple. Apparently the UI runs in
a special thread that can't be accessed by other
threads directly. After a lot of digging I found some
SWT snippets where some Display methods (syncExec,
asyncExec) enable updating UI thread. Working so far.
What a pain. Thanks.

Have the gui register with the task implementation as a listener. When the task is done, have the task call the listener method.

If that doesnt help you might want to tell me what exactly you want to do with the UI when the task is done.
 
This topic has 6 replies on 1 page.