-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKeyEventDemo.java
More file actions
38 lines (30 loc) · 992 Bytes
/
Copy pathKeyEventDemo.java
File metadata and controls
38 lines (30 loc) · 992 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/*
* This Program shows example of how we implement key listener
* uses Applet to demonstrate
*/
import java.applet.Applet;
import java.awt.event.*;
import java.awt.*;
public class KeyEventDemo extends Applet implements KeyListener {
String message = "";
public void init() {
addKeyListener(this); // this registers KeyListener to KeyEventDemo Applet class
}
public void keyTyped(KeyEvent e) {
showStatus("Key Typed");
message = message + e.getKeyChar();
repaint(); // repaints the component (i.e. applet in this example) on each key typed event triggered
}
public void keyPressed(KeyEvent e) {
showStatus("Key Pressed"); // shows them text in status bar of applet
}
public void keyReleased(KeyEvent e) {
showStatus("Ley Released");
}
public void paint(Graphics g) {
g.drawString(message, 50, 50);
}
}
/*
<applet code="KeyEventDemo" height="400" width="400" ></applet>
*/