The initO Method iNvoked when the applet is first loaded and again if the applet is reloaded O A subclass of applet should override this method if the subclass has an initialization to perform o The functions usually implemented in this method include creating new threads, loading images, setting up user-interface components, and getting string parameter values from the <applet tag in the html page Introduction to Java Programming, revised by Dai-kaiyu
Liang,Introduction to Java Programming,revised by Dai-kaiyu 11 The init() Method ⚫Invoked when the applet is first loaded and again if the applet is reloaded. ⚫A subclass of Applet should override this method if the subclass has an initialization to perform. ⚫ The functions usually implemented in this method include creating new threads, loading images, setting up user-interface components, and getting string parameter values from the <applet> tag in the HTML page
The start Method iNvoked after the inito method is executed; also called whenever the applet becomes active again after a period of inactivity(for example, when the user returns to the page containing the applet after surfing other Web pages) oA subclass of applet overrides this method if it has any operation that needs to be performed whenever the Web page containing the applet is visited. An applet with animation, for example, might use the start method to resume animation Introduction to Java Programming, revised by Dai-kaiyu
Liang,Introduction to Java Programming,revised by Dai-kaiyu 12 The start() Method ⚫Invoked after the init() method is executed; also called whenever the applet becomes active again after a period of inactivity (for example, when the user returns to the page containing the applet after surfing other Web pages). ⚫A subclass of Applet overrides this method if it has any operation that needs to be performed whenever the Web page containing the applet is visited. An applet with animation, for example, might use the start method to resume animation
The stop method The opposite of the start method, which is called when the user moves back to the page containing the applet; the stop method is invoked when the user moves off the page A subclass of Applet overrides this method if it has any operation that needs to be performed each time the Web page containing the applet is no longer visible. When the user leaves the page, any threads the applet has started but not completed will continue to run. You should override the stop method to suspend the running threads so that the applet does not take up system resources when it is inactive Introduction to Java Programming, revised by Dai-kaiyu
Liang,Introduction to Java Programming,revised by Dai-kaiyu 13 The stop() Method ⚫The opposite of the start() method, which is called when the user moves back to the page containing the applet; the stop() method is invoked when the user moves off the page. ⚫A subclass of Applet overrides this method if it has any operation that needs to be performed each time the Web page containing the applet is no longer visible. When the user leaves the page, any threads the applet has started but not completed will continue to run. You should override the stop method to suspend the running threads so that the applet does not take up system resources when it is inactive
The destroyO Method iNvoked when the browser exits normally to inform the applet that it is no longer needed and that it should release any resources it has allocated a subclass of applet overrides this method if it has any operation that needs to be performed before it is destroyed. Usually, you won't need to override this method unless you wish to release specific resources, such as threads that the applet created Introduction to Java Programming, revised by Dai-kaiyu
Liang,Introduction to Java Programming,revised by Dai-kaiyu 14 The destroy() Method ⚫Invoked when the browser exits normally to inform the applet that it is no longer needed and that it should release any resources it has allocated. ⚫A subclass of Applet overrides this method if it has any operation that needs to be performed before it is destroyed. Usually, you won't need to override this method unless you wish to release specific resources, such as threads that the applet created
applet methods Action Browser ● Applet methods are called by y the Browser starts your applet class file init() init(method completes start browser start()method invokes aIn o Different browser Exposure by other window paint events result inExposure by other window paint calls to the Your applet code explicitly asks it to repaint0→> update(0→> paint0 repaint methods (ie: user clicks Clear button on your GUn User pages to another page stop User pages back to your page start(→> paint0 User minimizes browser User maximizes browser start0→> paint(0 Introduction to Java Programming, revised by Dai-kaiyu
Liang,Introduction to Java Programming,revised by Dai-kaiyu 15 applet methods ⚫ Applet methods are called by the browser ⚫ Different browser events result in calls to the methods