Java Applet With All LifeCycle Methods

LEVEL: Beginner

Whats in this post?

  1. Code
  2. Output
  3. Background and Explanation of the code


To copy code: Click  View Source “View Source” on the right of this code snippet.

Background and Explanation of the codeIn this program you will learn about the lifecycle of an applet and different methods of an applet. Applet runs in the browser and its lifecycle method are called by JVM when it is loaded and destroyed. Here are the lifecycle methods of an Applet:

init(): This method is called to initialized an applet

start(): This method is called after the initialization of the applet.

stop(): This method can be called multiple times in the life cycle of an Applet.

destroy(): This method is called only once in the life cycle of the applet when applet is destroyed.

To compile the program: javac

To run the program: appletviewer

The attached output displays the Applet window. You can see the printed statements on command-prompt, these will help you to test and understand Applet’s life cycle. You can minimize and maximize the Applet window and check what statements are printed on command-prompt.