-
Notifications
You must be signed in to change notification settings - Fork 0
/
KeyEventDemo.java
71 lines (55 loc) · 1.32 KB
/
KeyEventDemo.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package keyeventdemo;
import java.awt.*;
import java.awt.event.*;
import java.util.Date;
class MyFrame extends Frame implements KeyListener
{
Label l1,l2,l3,l4;
public MyFrame()
{
super("KeyEvent Demo");
l1=new Label("");
l2=new Label("");
l3=new Label("");
l4=new Label("");
setLayout(null);
l1.setBounds(30,10,100,20);
l2.setBounds(30, 40,100,20);
l3.setBounds(30,70,100,20);
l4.setBounds(30,110,200,20);
add(l1);
add(l2);
add(l3);
add(l4);
addKeyListener(this);
}
@Override
public void keyPressed(KeyEvent e)
{
l1.setText("keypressed");
l2.setText("");
}
@Override
public void keyReleased(KeyEvent e) {
l2.setText("keyreleased");
l1.setText("");
l3.setText("");
l4.setText("");
}
@Override
public void keyTyped(KeyEvent e)
{
l3.setText("key Typed");
l4.setText(new Date(e.getWhen())+"");
}
}
public class KeyEventDemo {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
MyFrame f=new MyFrame();
f.setSize(500,500);
f.setVisible(true);
}
}