This week's book giveaway is in the Mac OS forum. We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line! See this thread for details.
# init: This method is intended for whatever initialization is needed for your applet. It is called after the param attributes of the applet tag. # start: This method is automatically called after init method. It is also called whenever user returns to the page containing the applet after visiting other pages. # stop: This method is automatically called whenever the user moves away from the page containing applets. You can use this method to stop an animation. # destroy: This method is only called when the browser shuts down normally.
The example in Java Tutorial seems don't work that way. When I first launch this example via:http://java.sun.com/docs/books/tutorial/deployment/applet/index.html It prints: initializing... starting... as expected. Then I switch to another window(ex. my NetBeans IDE), then switch back to the browser. It doesn't print: stopping... starting... Maybe the switch action should be invoked within browser. So I click another link from the Applet page, then go back. It prints: stopping... preparing for unloading... initializing... starting... It's not what I expected either. Is my understanding of these methods wrong? How to let that example print stopping... starting... by turns?
stop will be called if the window containing the applet is closed, or if the page is replaced by a different one, not if the page is merely switched to the background.
You'll rarely see stop and start without an intervening init call, because applet instances are not cached between page views. This page implies otherwise, but I think the sentence "Some browsers reload the applet when you return to its page." actually means "All browsers reload the applet when you return to its page." [ June 18, 2007: Message edited by: Ulf Dittmer ]
Originally I want to use the feature I thought to improve the performance. My applet poll a device to update status every 1 second. When the applet runs into background, it's better to stop polling. I have to find another way now.