applet

Applet lifecycle methods

In this example we shall show you the Applet lifecycle methods. A Java applet is a special kind of Java program that a browser enabled with Java technology can download from the internet and run. An applet is typically embedded inside a web page and runs in the context of a browser. An applet must be a subclass of the java.applet.Applet class. The Applet class provides the standard interface between the applet and the browser environment. The Applet lifecycle methods are the ones below:

  • init() API method is called by the browser or applet viewer to inform this applet that it has been loaded into the system.
  • start() API method is called by the browser or applet viewer to inform this applet that it should start its execution.
  • stop() API method is called by the browser or applet viewer to inform this applet that it should stop its execution.
  • destroy() API method is called by the browser or applet viewer to inform this applet that it is being reclaimed and that it should destroy any resources that it has allocated.
  • paint(Graphics g) API method is used to paint the container of the applet. This forwards the paint to any lightweight components that are children of this container,

as described in the code snippet below.

package com.javacodegeeks.snippets.core;

import java.applet.Applet;
import java.awt.Graphics;

public class AppletLifecycleMethods extends Applet {
	
	private static final long serialVersionUID = 5872447536017036208L;

	// Called by the browser or applet viewer to inform
	// this applet that it has been loaded into the system.
    public void init() {
    }

    // Called by the browser or applet viewer to inform
    // this applet that it should start its execution.
    public void start() {
    }

    // Called by the browser or applet viewer to inform
    //this applet that it should stop its execution.
    public void stop() {
    }

    // Called by the browser or applet viewer to inform
    // this applet that it is being reclaimed and that it
    // should destroy any resources that it has allocated.
    // The stop method will always be called before destroy. 
    public void destroy() {
    }

    // Paints the container. This forwards the paint to any
    // lightweight components that are children of this container.
    public void paint(Graphics g) {
    }

}
<applet code=com.javacodegeeks.snippets.core.AppletLifecycleMethods width=100 height=100>
</applet>

 
This was an example of Applet lifecycle methods in Java.

Want to know how to develop your skillset to become a Java Rockstar?

Join our newsletter to start rocking!

To get you started we give you our best selling eBooks for FREE!

 

1. JPA Mini Book

2. JVM Troubleshooting Guide

3. JUnit Tutorial for Unit Testing

4. Java Annotations Tutorial

5. Java Interview Questions

6. Spring Interview Questions

7. Android UI Design

 

and many more ....

 

Receive Java & Developer job alerts in your Area

I have read and agree to the terms & conditions

 

Ilias Tsagklis

Ilias is a software developer turned online entrepreneur. He is co-founder and Executive Editor at Java Code Geeks.
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Inline Feedbacks
View all comments
Back to top button