[text] hii

Viewer

  1. import java.awt.*;
  2. import java.awt.event.*;
  3. import java.applet.*;
  4.  
  5. /*
  6. <applet code="KeyEvents.class" height=500 width=600>
  7.  </applet>
  8. */
  9. public class KeyEvents extends Applet implements KeyListener {
  10.     int x = 20, y = 30;
  11.     String msg = " ";
  12.  
  13.     public void init() {
  14.         addKeyListener(this);
  15.         setBackground(Color.green);
  16.         setForeground(Color.blue);
  17.     }
  18.  
  19.     public void keyPressed(KeyEvent k) {
  20.         showStatus("Key Down");
  21.     }
  22.  
  23.     public void keyReleased(KeyEvent k) {
  24.         showStatus("Key Up");
  25.     }
  26.  
  27.     public void keyTyped(KeyEvent k) {
  28.         msg += k.getKeyChar();
  29.         repaint();
  30.     }
  31.  
  32.     public void paint(Graphics g) {
  33.         g.drawString(msg, x, y);
  34.     }
  35. }
  36.  

Editor

You can edit this paste and save as new:


File Description
  • hii
  • Paste Code
  • 16 Apr-2024
  • 747 Bytes
You can Share it: