SlideShare a Scribd company logo
2
Most read
3
Most read
4
Most read
Applet Life Cycle in Java
In Java, an applet is a special type of program embedded in the web
page to generate dynamic content. Applet is a class in Java.
The applet life cycle can be defined as the process of how the object is
created, started, stopped, and destroyed during the entire execution of
its application. It basically has five core methods namely init(), start(),
stop(), paint() and destroy().These methods are invoked by the browser
to execute.
Along with the browser, the applet also works on the client side, thus
having less processing time.
Methods of Applet Life Cycle
• There are five methods of an applet life cycle, and they are
• init(): The init() method is the first method to run that initializes the
applet. It can be invoked only once at the time of initialization. The
web browser creates the initialized objects, i.e., the web browser
(after checking the security settings) runs the init() method within the
applet.
• start(): The start() method contains the actual code of the applet and
starts the applet. It is invoked immediately after the init() method is
invoked. Every time the browser is loaded or refreshed, the start()
method is invoked. It is also invoked whenever the applet is
maximized, restored, or moving from one tab to another in the
browser. It is in an inactive state until the init() method is invoked.
• stop(): The stop() method stops the execution of the applet. The stop
() method is invoked whenever the applet is stopped, minimized, or
moving from one tab to another in the browser, the stop() method is
invoked. When we go back to that page, the start() method is invoked
again.
• destroy(): The destroy() method destroys the applet after its work is
done. It is invoked when the applet window is closed or when the tab
containing the webpage is closed. It removes the applet object from
memory and is executed only once. We cannot start the applet once
it is destroyed.
• paint(): The paint() method belongs to the Graphics class in Java. It is
used to draw shapes like circle, square, trapezium, etc., in the applet.
It is executed after the start() method and when the browser or
applet windows are resized.
• Sequence of method execution when an applet is executed:
• init()
• start()
• paint()
• Sequence of method execution when an applet is executed:
• stop()
• destroy()
Applet Life Cycle Working
• The Java plug-in software is responsible for managing the life cycle of an
applet.
• An applet is a Java application executed in any web browser and works on
the client-side. It doesn't have the main() method because it runs in the
browser. It is thus created to be placed on an HTML page.
• The init(), start(), stop() and destroy() methods belongs to
the applet.Applet class.
• The paint() method belongs to the awt.Component class.
• In Java, if we want to make a class an Applet class, we need to extend
the Applet
• Whenever we create an applet, we are creating the instance of the existing
Applet class. And thus, we can use all the methods of that class.
Flow of Applet Life Cycle:
class TestAppletLifeCycle extends Applet
{
public void init()
{
// initialized objects
}
public void start()
{
// code to start the applet
}
public void paint(Graphics graphics)
{
// draw the shapes
}
public void stop()
{
// code to stop the applet
}
public void destroy()
{
// code to destroy the applet
}
}
Delegation Event Model in Java
• The Delegation Event model is defined to handle events in
GUI programming languages. The GUI stands for Graphical User
Interface, where a user graphically/visually interacts with the system.
• The Event Delegation Model in java is a mechanism in Java for
handling events. It is based on a hierarchy of containers and
components, with event listeners registered at the top level of the
hierarchy. This allows the container to handle events for all of its
components, improving performance and reducing code duplication.
Event Processing in Java
• The below image demonstrates the event processing.
The modern approach for event processing is based on the Delegation
Model. It defines a standard and compatible mechanism to generate
and process events. In this model, a source generates an event and
forwards it to one or more listeners. The listener waits until it receives
an event. Once it receives the event, it is processed by the listener and
returns it. The UI elements are able to delegate the processing of an
event to a separate function.
Applet Life Cycle in Java with brief introduction
Advantage of the Delegation Event Model
• The advantages of using the Event Delegation Model in Java include
improved performance, reduced code duplication, increased
flexibility, and easier maintenance. The model allows developers to
create applications that are responsive, modular, and easy to
maintain.
• Basically, an Event Model is based on the following three
components:
• Events
• Events Sources
• Events Listeners
How Does the Event Delegation Model Work in
Java?
• The Event Delegation Model is a programming pattern used in Java for
handling events in GUI (Graphical User Interface) applications. It
follows a hierarchical structure, where the events are initially received
by the top-level container and then delegated to the appropriate
component for processing.

More Related Content

PPTX
Event handling
PPTX
Applets in java
PDF
Java threads
PPTX
Java applet
PPT
Java And Multithreading
PPTX
Java exception handling
PPTX
Java Server Pages
PPTX
JAVA AWT
Event handling
Applets in java
Java threads
Java applet
Java And Multithreading
Java exception handling
Java Server Pages
JAVA AWT

What's hot (20)

PPTX
Abstraction java
PDF
Servlet and servlet life cycle
PPTX
Java program structure
PPT
Final keyword in java
PPT
Introduction to method overloading & method overriding in java hdm
PPTX
Java abstract class & abstract methods
PPTX
Java swing
PPTX
Java package
PDF
Collections in Java Notes
PPTX
java interface and packages
PPTX
Method overloading
PDF
Collections In Java
PDF
PPTX
STRUCTURE OF SQL QUERIES
PPTX
Packages in java
PPSX
Java annotations
PPT
Exception Handling in JAVA
PDF
Java I/o streams
PPS
Java Exception handling
Abstraction java
Servlet and servlet life cycle
Java program structure
Final keyword in java
Introduction to method overloading & method overriding in java hdm
Java abstract class & abstract methods
Java swing
Java package
Collections in Java Notes
java interface and packages
Method overloading
Collections In Java
STRUCTURE OF SQL QUERIES
Packages in java
Java annotations
Exception Handling in JAVA
Java I/o streams
Java Exception handling
Ad

Similar to Applet Life Cycle in Java with brief introduction (20)

PPTX
21cs-403c-Concepts of Applets, AWT and Event handling- L1.pptx
PPT
Advanced Programming, Java Programming, Applets.ppt
PPTX
Java applet
PPT
Java programming Java programming Java programming
PPTX
Java Apple dndkorksnsbsjdkkdjejdjrdndjdj
PPTX
Applet (1)
PPT
Applet Architecture - Introducing Java Applets
PPTX
Applets in Java
PPTX
Applets in Java
PPTX
Applets
PPT
Basic of Applet
PDF
ITFT- Applet in java
PPTX
java.pptx
DOCX
Lecture1 oopj
PPTX
Appletjava
PDF
27 applet programming
PPTX
Applets in Java. Learn java program with applets
PPTX
PPTX
Applet1 (1).pptx
21cs-403c-Concepts of Applets, AWT and Event handling- L1.pptx
Advanced Programming, Java Programming, Applets.ppt
Java applet
Java programming Java programming Java programming
Java Apple dndkorksnsbsjdkkdjejdjrdndjdj
Applet (1)
Applet Architecture - Introducing Java Applets
Applets in Java
Applets in Java
Applets
Basic of Applet
ITFT- Applet in java
java.pptx
Lecture1 oopj
Appletjava
27 applet programming
Applets in Java. Learn java program with applets
Applet1 (1).pptx
Ad

Recently uploaded (20)

PPTX
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
PPTX
Geodesy 1.pptx...............................................
PPTX
Foundation to blockchain - A guide to Blockchain Tech
PPTX
Strings in CPP - Strings in C++ are sequences of characters used to store and...
PDF
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
PDF
Operating System & Kernel Study Guide-1 - converted.pdf
PDF
PPT on Performance Review to get promotions
PPTX
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
PDF
Model Code of Practice - Construction Work - 21102022 .pdf
PPTX
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
PPTX
OOP with Java - Java Introduction (Basics)
PDF
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
PDF
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
PDF
Embodied AI: Ushering in the Next Era of Intelligent Systems
PPTX
Welding lecture in detail for understanding
PPTX
Construction Project Organization Group 2.pptx
PDF
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
PPTX
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
PDF
Arduino robotics embedded978-1-4302-3184-4.pdf
PDF
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
Geodesy 1.pptx...............................................
Foundation to blockchain - A guide to Blockchain Tech
Strings in CPP - Strings in C++ are sequences of characters used to store and...
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
Operating System & Kernel Study Guide-1 - converted.pdf
PPT on Performance Review to get promotions
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
Model Code of Practice - Construction Work - 21102022 .pdf
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
OOP with Java - Java Introduction (Basics)
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
Embodied AI: Ushering in the Next Era of Intelligent Systems
Welding lecture in detail for understanding
Construction Project Organization Group 2.pptx
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
Arduino robotics embedded978-1-4302-3184-4.pdf
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026

Applet Life Cycle in Java with brief introduction

  • 1. Applet Life Cycle in Java In Java, an applet is a special type of program embedded in the web page to generate dynamic content. Applet is a class in Java. The applet life cycle can be defined as the process of how the object is created, started, stopped, and destroyed during the entire execution of its application. It basically has five core methods namely init(), start(), stop(), paint() and destroy().These methods are invoked by the browser to execute. Along with the browser, the applet also works on the client side, thus having less processing time.
  • 2. Methods of Applet Life Cycle
  • 3. • There are five methods of an applet life cycle, and they are • init(): The init() method is the first method to run that initializes the applet. It can be invoked only once at the time of initialization. The web browser creates the initialized objects, i.e., the web browser (after checking the security settings) runs the init() method within the applet. • start(): The start() method contains the actual code of the applet and starts the applet. It is invoked immediately after the init() method is invoked. Every time the browser is loaded or refreshed, the start() method is invoked. It is also invoked whenever the applet is maximized, restored, or moving from one tab to another in the browser. It is in an inactive state until the init() method is invoked.
  • 4. • stop(): The stop() method stops the execution of the applet. The stop () method is invoked whenever the applet is stopped, minimized, or moving from one tab to another in the browser, the stop() method is invoked. When we go back to that page, the start() method is invoked again. • destroy(): The destroy() method destroys the applet after its work is done. It is invoked when the applet window is closed or when the tab containing the webpage is closed. It removes the applet object from memory and is executed only once. We cannot start the applet once it is destroyed. • paint(): The paint() method belongs to the Graphics class in Java. It is used to draw shapes like circle, square, trapezium, etc., in the applet. It is executed after the start() method and when the browser or applet windows are resized.
  • 5. • Sequence of method execution when an applet is executed: • init() • start() • paint() • Sequence of method execution when an applet is executed: • stop() • destroy()
  • 6. Applet Life Cycle Working • The Java plug-in software is responsible for managing the life cycle of an applet. • An applet is a Java application executed in any web browser and works on the client-side. It doesn't have the main() method because it runs in the browser. It is thus created to be placed on an HTML page. • The init(), start(), stop() and destroy() methods belongs to the applet.Applet class. • The paint() method belongs to the awt.Component class. • In Java, if we want to make a class an Applet class, we need to extend the Applet • Whenever we create an applet, we are creating the instance of the existing Applet class. And thus, we can use all the methods of that class.
  • 7. Flow of Applet Life Cycle:
  • 8. class TestAppletLifeCycle extends Applet { public void init() { // initialized objects } public void start() { // code to start the applet } public void paint(Graphics graphics) { // draw the shapes } public void stop() { // code to stop the applet } public void destroy() { // code to destroy the applet } }
  • 9. Delegation Event Model in Java • The Delegation Event model is defined to handle events in GUI programming languages. The GUI stands for Graphical User Interface, where a user graphically/visually interacts with the system. • The Event Delegation Model in java is a mechanism in Java for handling events. It is based on a hierarchy of containers and components, with event listeners registered at the top level of the hierarchy. This allows the container to handle events for all of its components, improving performance and reducing code duplication.
  • 10. Event Processing in Java • The below image demonstrates the event processing. The modern approach for event processing is based on the Delegation Model. It defines a standard and compatible mechanism to generate and process events. In this model, a source generates an event and forwards it to one or more listeners. The listener waits until it receives an event. Once it receives the event, it is processed by the listener and returns it. The UI elements are able to delegate the processing of an event to a separate function.
  • 12. Advantage of the Delegation Event Model • The advantages of using the Event Delegation Model in Java include improved performance, reduced code duplication, increased flexibility, and easier maintenance. The model allows developers to create applications that are responsive, modular, and easy to maintain. • Basically, an Event Model is based on the following three components: • Events • Events Sources • Events Listeners
  • 13. How Does the Event Delegation Model Work in Java? • The Event Delegation Model is a programming pattern used in Java for handling events in GUI (Graphical User Interface) applications. It follows a hierarchical structure, where the events are initially received by the top-level container and then delegated to the appropriate component for processing.