O'Reilly logo

Sams Teach Yourself Java™ in 24 Hours, Sixth Edition by Rogers Cadenhead

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required