Video summary

Lecture 34: Applet Programming—I

Main summary

Key takeaways

Educational

Summary

The lecture introduces Java applet programming and reviews how an applet differs from a conventional Java application.

What an applet is

A Java applet is a small program embedded in a web page. Historically, it could be displayed by a browser or the Java Applet Viewer.

Applets were used to create graphical, interactive content, such as text, images, multimedia, and user-input features. Their visible area acts as a GUI: it can display content and, in more advanced examples, menus and other interface elements.

Basic applet structure and workflow

A simple applet typically:

  1. Imports relevant Java packages, commonly java.applet.* and java.awt.*.
  2. Declares a class that extends Applet.
  3. Implements methods such as paint(Graphics g) to draw content. For example, drawString can display “Hello World” at specified coordinates.
  4. Compiles the .java source file into a .class file.
  5. References the class file in an HTML file, with attributes specifying the display width and height.
  6. Opens the HTML file in an applet-capable browser or, as the lecture recommends, with the appletviewer tool.

The lecture notes that mainstream browsers generally no longer support Java applets, citing security concerns. Applet Viewer is presented as an alternative for running the examples.

Applet components

The lecture identifies three parts of the basic development process:

  • Java source file (.java): Contains the applet class and code.
  • Compiled class file (.class): Produced by compiling the Java source.
  • HTML file: Embeds the class file and specifies the applet’s dimensions and any parameters.

If compilation fails or the applet is not embedded correctly, the viewer may show a blank area.

Applet methods and lifecycle

The lecture introduces the following applet methods:

  • init() runs to initialize the applet. It can configure the applet or read values supplied through HTML.
  • start() begins or resumes applet activity after initialization.
  • stop() pauses activity when the applet is no longer active.
  • paint(Graphics g) draws or redraws the applet’s visible content.
  • destroy() performs cleanup when the applet is being removed.

An applet does not use a main() method as its entry point. Its lifecycle is managed by the applet environment.

Passing values from HTML

The lecture demonstrates supplying data through HTML parameters:

  1. Add named parameters—such as x, y, w, and h—to the applet’s HTML element.
  2. In init(), retrieve each value with getParameter().
  3. Convert the returned text to integers when numeric values are needed.
  4. Use the values in drawing code. For example, drawRect(x, y, w, h) draws a rectangle at the specified position and dimensions.

This lets the applet be configured through the HTML file without reading directly from the keyboard.

Applets versus applications

  • A Java application is a standalone program, normally started through its main() method and run with the Java command.
  • An applet is embedded in HTML and launched by an applet-capable viewer or browser. It does not have a main() method.
  • The lecture characterizes applets as more restricted than applications. It says they cannot directly use standard input/output, freely access files, launch other programs, or use arbitrary libraries. These restrictions are presented as security measures for code embedded in a web page.

Speakers and sources

  • Speaker: One lecturer, not identified by name in the subtitles.
  • Source: NPTEL IIT Kharagpur lecture, Lecture 34: Applet Programming—I.

Rate this summary

Your feedback will help improve summaries.

Improve this summary

Reprocess with a stronger model when the summary feels incomplete or inaccurate.

Pro

Translate summary in another language

Pro

Ask questions to this video

Chat for follow-up questions, clarifications, and source-backed answers.

Coming soon

Share this summary

Original video