Article View: borland.public.jbuilder.java.language
Article #17690Re: Events and listoners
From: John P. McGrath
Date: Mon, 19 Oct 1998 00:00
Date: Mon, 19 Oct 1998 00:00
44 lines
2371 bytes
2371 bytes
Richard Hawkes <rhawkes@nbtel.nb.ca> wrote: > Hi, I am writing a applet with JBuilder 2. My program runs a thread > that keeps checking a screen for a field of text to appear. When this > happens I want to trigger and event back in the main program. > I figured I could use the same functionality that a button event > uses. I would throw some kind of event from the Thread, and then the > Main program would have a listener that would be activated, and then it > would run some code. There really is not anything called a "main program" in a Java program. There is the thread that runs the main() method, but in most interactive Java programs that thread terminates shortly after you start your program. It usually creates a frame and makes it visible, and then exists. As a side effect of making the frame visible, the AWT creates several other threads that keep your program alive. Anything you throw must be derived from Throwable - this includes Exceptions and Errors, but not any event class. Also, it is not possible to throw a Throwable from one thread to another. When you throw a Throwable, it is passed back through the call chain of the thread they are thrown from. If nothing catches them then the thread dies. So this approach will not work. One of the threads created when you make your frame visible is the AWT event thread. It monitors the event queue, removing events from the queue when one is available, and dispatches them to the appropriate component. One approach you might try is to post an event to the AWT event queue. I have never done it, but it may work. Why is it that you want the code to run in a different thread than the one that detects the condition? And if this is really necessary, can you create another thread to process the "event"? -- Regards, John P. McGrath <mcgrath@enter.net> <jpm@nscs.fast.net>
Technical Details
Message-ID:
<MPG.1094c69a639864289896e1@forums.inprise.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<36262FC7.1511C37A@nbtel.nb.ca>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f74b3,97fd6f0b3e17a57e X-Google-Attributes: gidf74b3,public From: mcgrath@enter.net (John P. McGrath) Subject: Re: Events and listoners Date: 1998/10/19 Message-ID: <MPG.1094c69a639864289896e1@forums.inprise.com> X-Deja-AN: 402743723 References: <36262FC7.1511C37A@nbtel.nb.ca> Organization: Software Consulting Services Newsgroups: borland.public.jbuilder.java.language