Introduction to AWT and Applets · Introduction to Java Programming

Creating Applets

Watch lectures

Creating Applets

1. What Is an Applet? (beginner)

Applet = small Java program living in web page (browser ran it!). No main — browser calls init/start/paint/stop/destroy lifecycle! Historical (browsers dropped support ~2018 for security!) but exams still ask!

2. Lifecycle (exam order — memorize!)

import java.applet.Applet; // deprecated now! (exam still!)
import java.awt.*;
public class Hi extends Applet { // extends Applet (not Frame!)
    public void init() { setBackground(Color.YELLOW); } // 1. born (once!)
    public void start() { System.out.println("visible!"); } // 2. shown (many!)
    public void paint(Graphics g) { g.drawString("hi web!", 20, 20); } // 3. draw!
    public void stop() { System.out.println("hidden!"); }   // 4. minimized!
    public void destroy() { System.out.println("dead!"); }  // 5. closed!
}

HTML to run (old!): <applet code="Hi.class" width="300" height="200"></applet>

3. Applet vs Application (exam table!)

Applet Application (Frame!)
Entry init() (browser!) main() (JVM!)
Window browser page (no title!) own Frame!
Security sandboxed (no files!) full access!
Run HTML + browser/plugin java Class!

4. Modern Note (viva smart line!)

Browsers REMOVED applet plugins (security!). Today: same code as JPanel + JFrame, or Java Web Start / plain web apps. Learn lifecycle for exams, build Swing/Frame for real!

5. Exam Points

  • Lifecycle + program — 7 marks, very frequent.
  • Applet vs application — 5 marks, frequent.
Official AppAndroid App

PYQDeck for Android

Solve BEU previous-year exam papers anywhere, anytime. Fast search, offline paper viewing, and step-by-step solutions designed specifically for your phone.

← All Introduction to Java Programming modules