Back to Applets page
Click in the boxes below, select all and copy to grab the applet
HTML listing:
<HTML> <HEAD> <TITLE>Listing 8.5</TITLE> </HEAD> <BODY BGCOLOR=WHITE> <APPLET CODEBASE="classes" CODE="Applet5.class" WIDTH=500 HEIGHT=300> </APPLET> </BODY> </HTML>
Applet listing:
import java.awt.*; import java.applet.Applet; public class Applet5 extends Applet { TextField inputField; String displayText = "Enter a string to display"; String fontFace = "TimesRoman"; Choice fontMenu; public void init() { setBackground(Color.white); add(new Label("Text String:")); inputField = new TextField(20); add(inputField); fontMenu = new Choice(); fontMenu.addItem("TimesRoman"); fontMenu.addItem("Helvetica"); fontMenu.addItem("Courier"); fontMenu.addItem("Dialog"); fontMenu.addItem("DialogInput"); add(fontMenu); } public void paint(Graphics g) { g.setFont(new Font(fontFace,Font.PLAIN,24)); g.drawString(displayText,150,60); } public boolean action(Event e, Object arg) { if (e.target instanceof TextField) { displayText = inputField.getText(); repaint(); return true; } if (e.target instanceof Choice) { fontFace = (String) arg; repaint(); return true; } return false; } }