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 {
public void init() {
// Initialization tasks }
public void start() {
// Start tasks
}
public void paint(Graphics g) {
// Drawing tasks
g.drawString("Hello, this is my Java Applet!", 20, 20);
}
public void stop() {
// Stop tasks
}
public void destroy() {
// Cleanup tasks
}
}
KEY POINTS
• Applets are embedded in HTML using the <applet> tag.
• They require a compatible browser with Java plugin support (though
this support has decreased over time due to security concerns).
• Java Applets have largely been replaced by other web technologies
like HTML5, JavaScript, and CSS due to security vulnerabilities and
plugin dependency.
CONCLUSION
• Java Applets were once a significant technology for web interactivity.
• They belong to the java.applet package and follow a specific lifecycle.
• With the evolution of web technologies, their usage has declined in
favor of more modern and secure alternatives.
THANK YOU