1 / 10

Applet class

Applet class. The Applet class provides the essential framework that enables applets to be run by a web browser Applet do not have main method Applet depend on browser to call the methods. Define an applet class. Define an applet class Public MyApplet extends java.applet.Applet {

Rita
Download Presentation

Applet class

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Applet class • The Applet class provides the essential framework that enables applets to be run by a web browser • Applet do not have main method • Applet depend on browser to call the methods

  2. Define an applet class • Define an applet class • Public MyApplet extends java.applet.Applet • { // applet class methods • }

  3. Applet class methods • Every applet is made up of the following methods: • Constructor is called by the browser when the web page containing this applet is initially loaded, or reloaded • Public MyApplet(){ ....}

  4. Applet methods • Method init() called by the browser after the applet is loaded • Public void init(){ … } • start() called by the browser after the init() method, or every time the webpage is visited • Public void start(){ .. } • stop() called by the browser when the page containing this applet becomes inactive • Public void stop() { … } • destroy() called by the browser when the web browser exits • Public void destroy(){ … }

  5. Diagram of using methods Enters web page reload init() Return to page start() stop() Go to another page exits destroy()

  6. When a applet is loaded, the web browser creates an instance of the applet by invoking the constructor • The browser uses the init, start, stop, and destroy to control applet. • By default these methods do nothing • You need to modify in you applet so that the browser can call your code properly

  7. The init method • The init method is invoked after the applet is created or recreated. • A subclass of Applet should overrides this method if the subclass has an initialization to perform. • Usually includes creating new thread, loading images, setting up GUI components

  8. Start() method • The start method is invoked after the init method. • Called whenever the applet become active • A subclass of Applet overrides this method if it has any operation that needs to be performed whenever the webpage is visited. • An applet with animation might use the start method to resume animation

  9. Stop() method • The stop method is the opposite of the start method. • Is invoked when the user leave the page. • A subclass of Applet overrides this method if it has any operation that needs to be performed • When the user leaves the page, any threads that 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

  10. Destroy() method • The destroy() method is invoked when the browser exits normally to inform the applet that is no longer needed and should release any resources it has allocated. • The stop method is always called before the destroy method • 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

More Related