I've asked recently about dealing with Threads in Swing. Now I have one
other problem and I THINK the term I want is a callback, but it's hard to
find docs on this. Basically I have a primary Swing thread that has
invoked a subthread to process data while the display refreshes.
The 2nd thread is created with an entire external class (for many reasons).
When the 2nd thread finishes, I want it to be able to call the first class
back and update some data and tell it to display a message window. I know
I can use invokeLater() for the message window, and that way it'll be
handled by the main Swing thread, but there are several questions I have
about trying to set data in the calling class.
Is there a way to set up a listener in the calling class that the subthread
and class the subthread is in can trigger it?
I found I could not pass the class itself as a class, but had to pass it as
an object, then, inside the object, I can use Object.getClass() to get the
class, but that I can't cast the Object to class or get an actual instance
of the calling class. I can find a method, and then, from inside the
subthread class, call the method in the original calling class, but it
needs a new instance of the class, which, unless I am completely wrong,
will not contain the same data as the calling class -- it'll be a whole new
instance of it. Is there a way for a class to pass an instance of itself
as a parameter and for the called class to actually get that instance?
Is there a standard way to put a listener in a class and have another class
trigger an event of some kind or an exception that forces the first class
to handle it?
Thanks for any help!
Hal
Mark Thomas - 21 Jan 2006 16:13 GMT
> I've asked recently about dealing with Threads in Swing. Now I have one
> other problem and I THINK the term I want is a callback, but it's hard to
[quoted text clipped - 28 lines]
>
> Hal
You might like to take a look at SwingWorker
http://java.sun.com/docs/books/tutorial/uiswing/misc/threads.html#SwingWorker
Mark
opalpa@gmail.com opalinski from opalpaweb - 21 Jan 2006 16:29 GMT
Hey your message confuses me. Rewrite it more clearly please. Maybe
use the same name for certain threads, certain classes, and certain
instances. Or maybe post code.
Opalinski
opalpa@gmail.com
http://www.geocities.com/opalpaweb/
Thomas Hawtin - 22 Jan 2006 18:32 GMT
> Is there a standard way to put a listener in a class and have another class
> trigger an event of some kind or an exception that forces the first class
> to handle it?
I'm finding it difficult to follow what you are trying to get. But,
almost certainly you don't want anything to do with java.lang.Class
objects in this situation. Think objects instead of classes (and
delegation instead of inheritance).
Don't think about getting one object to cause an event in a second.
Think about the first object invokes a meaningful operation through the
public interface of the second object. The implementation of the second
object happens to fire an event in response.
Really, I think we need to have an idea of what you are trying to
achieve at a higher level.
Tom Hawtin

Signature
Unemployed English Java programmer
http://jroller.com/page/tackline/