-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhandlingKeyEvent.java
More file actions
61 lines (47 loc) · 1.22 KB
/
handlingKeyEvent.java
File metadata and controls
61 lines (47 loc) · 1.22 KB
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
import java.awt.*;
import java.awt.event.*;
import java.sql.Date;
class myframe extends Frame implements KeyListener
{
Label l1,l2,l3,l4;
public myframe()
{
super("key event demo");
l1 = new Label("");
l2 = new Label("");
l3 = new Label("");
l4 = new Label("");
setLayout(null);
l1.setBounds(30, 40, 100, 20);
l2.setBounds(30, 60, 100, 20);
l3.setBounds(30, 80, 100, 20);
l4.setBounds(30, 100, 100, 20);
add(l1);
add(l2);
add(l3);
add(l4);
addKeyListener(this);
}
public void keyTyped(KeyEvent e) {
l3.setText("key typed");
l4.setText(new Date(e.getWhen())+"");
}
public void keyPressed(KeyEvent e) {
l1.setText("key pressed");
l2.setText("");
}
public void keyReleased(KeyEvent e) {
l2.setText("Key Released");
l1.setText("");
l3.setText("");
l4.setText("");
}
}
public class handlingKeyEvent {
public static void main(String arg[])
{
myframe f = new myframe();
f.setSize(400,400);
f.setVisible(true);
}
}