A Sample 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'll take a look at 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.

Load your word processor and create a new file called SalutonApplet.java. Enter the text of Listing 17.1 into the file and save it when you're done.

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 ...

Get SAMS Teach Yourself Programming with Java™ in 24 Hours, FOURTH 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.