WHAT IS ANAPPLET
• An applet is a small Java program that runs inside a web browser or
applet viewer.
• Designed to provide interactive features on web pages.
• Extends the java.applet.Applet class.
• Unlike regular Java programs, applet programs do not have a main()
method.
3.
FEATURES OF APPLETS
•Runs in a browser or applet viewer.
• Can create GUI components using AWT or Swing.
• Secure: runs in a sandbox environment.
• Cannot access local files directly (unless signed).
• Can respond to events like mouse click, key press, etc.
4.
TYPES OF APPLETS
•A. Based on Lifecycle
• Static Applets: Display fixed output; do not respond to user interaction.
• Dynamic Applets: Respond to user events and actions.
• B. Based on Security
• Unsigned Applets: Default, restricted in permissions.
• Signed Applets: Can access local resources if verified.
Method Purpose
init() Calledonce to initialize the applet.
start()
Called every time the applet
becomes visible.
paint(Graphics g)
Called to draw on the applet
screen.
stop()
Called when the applet is no longer
visible.
destroy()
Called once before the applet is
destroyed.
COMPILE AND RUN
•HTML file to run the applet:
<applet code="HelloApplet.class" width="300"
height="300"></applet>
• Compile: javac HelloApplet.java
• Run in applet viewer: appletviewer HelloApplet.html
9.
ADVANTAGES OF APPLETS
•Interactive content for web pages.
• Can draw graphics and handle events.
• Secure execution in sandbox.
• Reusable code modules.
10.
DISADVANTAGES OF APPLETS
•Dependent on browser support (many modern
browsers no longer support).
• Restricted access to local files.
• Slower execution compared to applications.