-
Notifications
You must be signed in to change notification settings - Fork 0
/
KeyListenerEx.java
48 lines (42 loc) · 993 Bytes
/
KeyListenerEx.java
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
39
40
41
42
43
44
45
46
47
48
import java.awt.*;
import java.awt.event.*;
public class KeyListenerEx extends Frame implements KeyListener
{
String msg = "";
test()
{
addKeyListener(this);
setSize(400,400);
setLayout(null);
setVisible(true);
setBackground(Color.cyan);
}
public void keyPressed(KeyEvent e)
{
int key = e.getKeyCode();
switch(key)
{
case KeyEvent.VK_F1: msg += "<F1>";break;
case KeyEvent.VK_PAGE_UP: msg += "<PgUp>";break;
case KeyEvent.VK_LEFT: msg += "<Left Arrow>";break;
}
repaint();
}
public void keyReleased(KeyEvent e)
{
repaint();
}
public void keyTyped(KeyEvent e)
{
msg +=e.getKeyChar();
repaint();
}
public void paint(Graphics g)
{
g.drawString(msg, 50, 50);
}
public static void main(String[] args)
{
new KeyListenerEx();
}
}