Creating an Applet

This hour’s first project is an applet that displays the string “Saluton mondo!”, the traditional Esperanto greeting that is becoming more traditional by the hour. You get a feel for how applets are structured by re-creating the Saluton application from Hour 2, “Writing Your First Program,” as a program that can run on a web page.

Create a new empty Java file called SalutonApplet, enter the text from Listing 17.1 into the file, and save the file.

Listing 17.1. The Full Text of SalutonApplet.java

 1: import java.awt.*; 2: 3: public class SalutonApplet extends javax.swing.JApplet { 4:     String greeting; 5: 6:     public void init() { 7:         greeting = "Saluton mondo!"; 8:     } 9:10:     public void paint(Graphics screen) ...

Get Sams Teach Yourself Java™ in 24 Hours, Sixth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.