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