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 / First Aid / January 2006

Tip: Looking for answers? Try searching our database.

Callbacks -- Or Activating the Main Swing Thread

Thread view: 
Hal Vaughan - 21 Jan 2006 02:55 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
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/



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.