home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Java by Example
/
jbecd.bin
/
JBE-CD
/
NTUsers
/
JBECODE.ZIP
/
JavaByExample
/
chap25
/
KeyApplet.java
< prev
next >
Wrap
Text File
|
1996-03-12
|
650b
|
37 lines
import java.awt.*;
import java.applet.*;
public class KeyApplet extends Applet
{
int keyPressed;
public void init()
{
keyPressed = -1;
Font font =
new Font("TimesRoman", Font.BOLD, 144);
setFont(font);
resize(200, 200);
}
public void paint(Graphics g)
{
String str = "";
if (keyPressed != -1)
{
str += (char)keyPressed;
g.drawString(str, 40, 150);
}
}
public boolean keyDown(Event evt, int key)
{
keyPressed = key;
repaint();
return true;
}
}