Back to Applets page
Click in the boxes below, select all and copy to grab the applet
HTML listing:
<HTML> <HEAD> <TITLE>Listing 7.4</TITLE> </HEAD> <BODY BGCOLOR=WHITE> <TABLE BORDER=1 CELLPADDING=0 CELLSPACING=0><TR><TD> <APPLET CODEBASE="classes" CODE="Applet4.class" WIDTH=500 HEIGHT=100> </APPLET> </TD></TR></TABLE> </BODY> </HTML>
Applet listing:
import java.awt.*; import java.applet.*; public class Applet4 extends Applet { char currentChar = ' '; public void init() { setBackground(Color.white); setFont(new Font("Times Roman",Font.BOLD,36)); } public boolean keyDown(Event evt, int x) { currentChar = (char)x; repaint(); return true; } public void paint(Graphics g) { g.drawString(String.valueOf(currentChar),200,50); } }