Java Applets
Java Applets
-22AG1A0557
SIDDHARTHA
INTRODUCTION TO JAVA APPLETS
WHAT ARE APPLETS ?
• Java is a special type of program that is embedded in the web page to
generate dynamic content.
• It runs inside the browser and works at client side
• They were popular in the early days of the internet for creating
interactive web content.
• They are written in the Java programming language and are
embedded in an HTML page.
PACKAGE
• Applets are part of the java.applet package.
• They extend the java.applet.Applet class.
• Other relevant packages include java.awt for UI components
and java.net for networking functionalities.
LIFE CYCLE OF APPLET
• INITIALISATION – init()
• STARTING – start()
• RUNNING – paint()
• STOPPING – stop()
• DESTROYING – destroy()
• Initialization (init()):
The applet is initialized by calling the init() method.
Initialization includes setting up variables, loading resources, etc.
• Starting (start()):
After initialization, the applet enters the start phase.
The start() method is called, initiating the applet's execution.
• Running:
The applet is running and can respond to user interaction or perform
tasks.
• Stopping (stop()):
If the applet loses focus or the user navigates away from the page, the
stop() method is called.
Applet's execution pauses, but it remains in memory.
• Destroying (destroy()):
When the applet is no longer needed (e.g., the browser window is
closed), the destroy() method is called.
Resources are released, and the applet is terminated.
SAMPLE CODE
import java.applet.Applet;
import java.awt.*;
/* <applet code=“MyApplet” height =“50” width=“50”>
</applet> */
public class MyApplet extends Applet {