import java.awt.*; import java.awt.event.*; import java.applet.*; public class KeyDown extends Applet implements KeyListener { private String keyChar = null; private int x = 0, y = 100; private boolean keyIsDown = false; public KeyDown() { addKeyListener(this); } public void keyPressed(KeyEvent evt) { keyIsDown = true; keyChar = evt.getKeyChar()+""; repaint(); } public void keyTyped(KeyEvent evt) { } public void keyReleased(KeyEvent evt) { keyIsDown = false; repaint(); } public void paint(Graphics g) { if (keyIsDown) { g.setColor(Color.red); g.setFont(new Font("Times New Roman", Font.BOLD, 48)); g.drawString(keyChar, (x + 40), (y + 60)); System.out.println(keyChar); g.setColor(Color.black); g.fillOval(x, y, 100, 100); } else { g.setColor(Color.lightGray); g.fillOval(x, y, 100, 100); } } public void update(Graphics g){ paint(g); } }