-
Notifications
You must be signed in to change notification settings - Fork 0
/
KeyListen.java
41 lines (35 loc) · 1.01 KB
/
KeyListen.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
import java.awt.*;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
public class KeyListen extends Frame {
TextArea area;
Label label;
KeyListen(){
// creating the label
label = new Label();
label.setBounds(30,50,150,30);
area = new TextArea();
area.setBounds(20,100,290,290);
area.addKeyListener(new KeyListener() {
@Override
public void keyTyped(KeyEvent e) {
label.setText("Key Typed");
}
@Override
public void keyPressed(KeyEvent e) {
label.setText("Key Pressed");
}
@Override
public void keyReleased(KeyEvent e) {
label.setText("Key released");
}
});
add(label);add(area);
setLayout(null);
setSize(400,400);
setVisible(true);
}
public static void main(String[] args) {
new KeyListen();
}
}