Back to Applets page
Click in the boxes below, select all and copy to grab the applet
HTML listing:
<HTML> <HEAD> <TITLE>My First Applet</TITLE> </HEAD> <BODY BGCOLOR=WHITE> <APPLET CODEBASE="Classes" CODE="HelloWorld.class" WIDTH=400 HEIGHT=50> <PARAM NAME=whatToSay VALUE="Hello, readers!"> </APPLET> </BODY> </HTML>
Applet listing:
/* This is my first applet */ import java.awt.*; public class HelloWorld extends java.applet.Applet { Font f = new Font("TimesRoman",Font.BOLD,36); String whatToSay; public void init() { setBackground(Color.white); this.whatToSay = getParameter("whatToSay"); // This is passed from HTML if (this.whatToSay == null) { this.whatToSay = "Hello, world!"; } } public void paint(Graphics g) { g.setFont(f); g.drawString(this.whatToSay, 100 , 25); } }