Back to Applets page
Click in the boxes below, select all and copy to grab the applet
HTML listing:
<HTML> <HEAD> <TITLE>Listing 11.3</TITLE> <SCRIPT LANGUAGE="JAVASCRIPT"> <!-- Hide script from old browsers function startUp() { document.myApplet.newText(prompt("What do you want to say?","")) } // End hiding script from old browsers --> </SCRIPT> </HEAD> <BODY onLoad="startUp()" BGCOLOR=WHITE> <APPLET CODEBASE="classes" CODE="Applet1.class" WIDTH=300 HEIGHT=50 NAME="myApplet"> </APPLET> </BODY> </HTML>
Applet listing:
import java.applet.*; import java.awt.*; public class Applet1 extends Applet { Font f = new Font("TimesRoman",Font.BOLD,36); String whatToSay; public void init() { setBackground(Color.white); } public void paint(Graphics g) { g.setFont(f); g.drawString(this.whatToSay, 100 , 25); } public void newText(String s) { this.whatToSay = s; repaint(); } }