Back to Scripts page
Click in the text area below, select all and copy to grab the script
Script 9.3 listing:
<HTML> <HEAD> <TITLE>Write to Java</TITLE> <SCRIPT LANGUAGE=JAVASCRIPT TYPE="TEXT/JAVASCRIPT"> <!-- Hide script from old browsers function startUp() { tempText = prompt("What do you want to say?","") if (tempText.length > 20) { alert("That line is too long") startUp() } else { document.myApplet.newText(tempText) } } // End hiding script from old browsers --> </SCRIPT> </HEAD> <BODY onLoad="startUp()" BGCOLOR=WHITE> <APPLET CODE="Applet1.class" WIDTH=600 HEIGHT=50 NAME="myApplet"> </APPLET> </BODY> </HTML>
Script 9.4 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(); } }