Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / February 2007

Tip: Looking for answers? Try searching our database.

Using SwingWorker with user interaction

Thread view: 
Efi Merdler - 24 Feb 2007 19:50 GMT
Hello,
I have a main GUI which uses a SwingWorker class in order to dispatch
a lengthy operation, this lengthy operation is required to update the
user interface, something that can be done quite easily using publish
method,in addition I need to retrieve keyboard clicks which also
causes the user interface to get updated.

In other words, I have a GUI and an engine that runs in the background
this engine needs to retrieve user interaction with the keyboard and
according to a keyboard click change the graphical interface.

My question is, should I divide the above operations (GUI and engine)
into two different threads, if so how do I make them share data
(keyboard --> engine engine --> gui) or maybe everything should run in
the same thread ?

What do you think ?

Thanks,
Efi
Knute Johnson - 24 Feb 2007 23:25 GMT
> Hello,
> I have a main GUI which uses a SwingWorker class in order to dispatch
[quoted text clipped - 16 lines]
> Thanks,
> Efi

I think I would make three SwingWorkers and after each is finished bring
up a dialog and ask the user for the input that you need.  Then proceed.

Signature

Knute Johnson
email s/nospam/knute/

Dan Andrews - 25 Feb 2007 04:50 GMT
[snip]
> In other words, I have a GUI and an engine that runs in the background
> this engine needs to retrieve user interaction with the keyboard and
> according to a keyboard click change the graphical interface.
[snip]

I agree with Knute Johnson, however, you might try a well placed
SwingUtilities.invokeAndWait in your background task.

Alternately and perhaps better, you might consider adding a method to
your SwingWorker's implementation to pass in notification of the key
event (e.g. set/getKeybordEvent which would be synchronized). When
your background task is iterating its work, periodically check the
getKeybordEvent method. Next, as you indicated, publish and update the
GUI in the process method.

Cheers,
Dan Andrews
-----------
http://www.ansir.ca


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.