...
> I have an applet embedded in html and a while-true-loop is running
>in the applet. When the applet is running, I type another URL
>(e.g. http://www.google.com), then what event will be triggered or
Applet stop or destroy might be called on
minimise and page unload.
Applet.destroy() // though some browsers do not call it
A (for example) rendering applet might also call a stop
in Applet.stop().
> ..how can I stop the while-true-loop on this event?
Make it a while-classAttribute-true boolean. Set
the attribute from stop and destroy (as well as
init()/start()).

Signature
Andrew Thompson
http://www.athompson.info/andrew/
tony - 17 Jun 2007 09:34 GMT
> ..
>> I have an applet embedded in html and a while-true-loop is running
[quoted text clipped - 13 lines]
> the attribute from stop and destroy (as well as
> init()/start()).
Actually, I wrote:
System.out.println("** destroying...");
in destroy() and
System.out.println("** stopping...");
in stop(), but nothing happened!
Neither of them was printed when I switch
to another page.
Andrew Thompson - 17 Jun 2007 10:50 GMT
>> ..
>>> I have an applet embedded in html and a while-true-loop is running
...
>> the attribute from stop and destroy (as well as
>> init()/start()).
>
>Actually, I wrote:
>System.out.println("** destroying...");
...
>Neither of them was printed when I switch
>to another page.
Web start* seems to call stop() and destroy()
reliably at applet close. * That results in a free
floating applet on launch. e.g.
<http://www.physci.org/jws/#jtest>

Signature
Andrew Thompson
http://www.athompson.info/andrew/
> I have an applet embedded in html and a while-true-loop is running
>in the applet. When the applet is running, I type another URL
>(e.g. http://www.google.com), then what event will be triggered or how
>can I stop the while-true-loop on this event?
You should not do that in an Applet since all Applets on a page share
the same thread. You should spawn a separate thread or arrange to get
an event periodically to do a little work. See
http://mindprod.com/jgloss/thread.html
http://mindprod.com/jgloss/timer.html
If you tie up the main thread no Swing painting can happen either.
.
--
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
tony - 17 Jun 2007 09:39 GMT
>> I have an applet embedded in html and a while-true-loop is running
>> in the applet. When the applet is running, I type another URL
[quoted text clipped - 13 lines]
> The Java Glossary
> http://mindprod.com
If I use threads to do it, how can I interrupt it or destroy it
when I switch to another page?
The key problem is that either destroy() or stop() is not called
and I don't know if there is any other event will be triggered?
Roedy Green - 22 Jun 2007 12:08 GMT
>If I use threads to do it, how can I interrupt it or destroy it
>when I switch to another page?
>The key problem is that either destroy() or stop() is not called
>and I don't know if there is any other event will be triggered?
Threads share variables. There are all kinds of ways for threads to
communicate. See http://mindprod.com/jgloss/thread.html
This is pretty complicated. You might want to get a textbook to
explain it or poke around in the new java.util.concurrent package
which has canned solutions to common problems.
see http://mindprod.com/jgloss/queue.html
--
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com