JAVA APPLETS
DR.J.KALAVATHI
ASSISTANT PROFESSOR OF INFORMATIONTECHNOLOGY,
V.V.VANNIAPERUMAL COLLEGE FORWOMEN,
VIRUDHUNAGAR
WHAT IS AN APPLET
• 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.
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.
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.
APPLET LIFECYCLE METHODS
Method Purpose
init() Called once 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.
APPLET EXAMPLE
import java.applet.Applet;
import java.awt.Graphics;
public class HelloApplet extends Applet {
public void paint(Graphics g) {
g.drawString("Hello,Applet!", 50, 50);
}
}
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
ADVANTAGES OF APPLETS
• Interactive content for web pages.
• Can draw graphics and handle events.
• Secure execution in sandbox.
• Reusable code modules.
DISADVANTAGES OF APPLETS
• Dependent on browser support (many modern
browsers no longer support).
• Restricted access to local files.
• Slower execution compared to applications.

web browser or Java Applets with Example

  • 1.
    JAVA APPLETS DR.J.KALAVATHI ASSISTANT PROFESSOROF INFORMATIONTECHNOLOGY, V.V.VANNIAPERUMAL COLLEGE FORWOMEN, VIRUDHUNAGAR
  • 2.
    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.
  • 5.
  • 6.
    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.
  • 7.
    APPLET EXAMPLE import java.applet.Applet; importjava.awt.Graphics; public class HelloApplet extends Applet { public void paint(Graphics g) { g.drawString("Hello,Applet!", 50, 50); } }
  • 8.
    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.