Java Applet Tutorial

A Java Applet is a small Java program built to run inside a web browser, using its own lifecycle and its own drawing surface instead of a normal main() method. This 18-lesson track covers applets end to end: the lifecycle, AWT graphics and events, images, audio, layout managers, and Swing's JApplet - using one running example, a simple Paint Applet that gains a new capability (color, mouse drawing, keyboard shortcuts, a background image) in each relevant lesson.

Be upfront about this up front: the applet API was deprecated in Java 9, marked "deprecated for removal" in Java 17, and has since been removed from current JDK releases entirely. No modern browser runs Java applets anymore - the browser plugin model they depended on (NPAPI) was phased out industry-wide around 2015-2016. You cannot ship a working applet to end users today. This track exists for three honest reasons: it still appears in some college syllabi and certification exams, the AWT event model it teaches is the direct ancestor of Swing's (and indirectly Android's) event handling, and you may still run into applet code in a legacy codebase. The last lesson, Deprecation & Alternatives, covers exactly what to reach for instead on a real project today.
Where this fits: Everything you write here runs with an old JDK (8 or earlier) using the appletviewer tool, not in an actual browser. If you're on a modern JDK, you can still compile and study the code - you just can't run it as a live applet without an old JDK on the side. See Environment Setup for exactly what that involves.

The Applet Lifecycle, at a Glance

init()  -->  start()  -->  paint()  -->  stop()  -->  destroy()
 once      resumable      redraws      pausable      once
          
MethodWhen it runs
init()Once, when the applet is first loaded - one-time setup
start()Every time the applet becomes visible - can run more than once
paint()Whenever the applet needs to redraw itself
stop()Every time the applet is hidden - pauses work
destroy()Once, right before the applet is unloaded for good

A Quick Look Ahead

Example: The Shape of Every Applet

import java.applet.Applet;
import java.awt.Graphics;

public class QuickLookApplet extends Applet {

  public void init() {
    // one-time setup, e.g. reading <param> values
  }

  public void paint(Graphics g) {
    g.drawString("Hello from an Applet!", 20, 30);
  }
}
Note: This page's code is a preview, not something you can run right on this website - this server runs PHP, not a Java runtime. Every example in this track is real, correct Java/AWT code meant to be compiled and run locally with an old JDK's appletviewer, as covered in Environment Setup.

What You'll Learn In This Track

AreaCovered in
FoundationsWhat an applet is, environment setup, and the full lifecycle
Your first appletsA first program, embedding it in HTML, and JApplet with Swing
Graphics & inputThe Graphics class, color & font, mouse events, keyboard events
Richer appletsApplet parameters, images, audio, layout managers, AWT components
Motion & wrap-upThreads & simple animation, then deprecation, alternatives, and best practices
Next steps: Head to What Is an Applet? for the history and the applet-vs-application comparison before writing any code.