-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKeyListenerDemo.java
More file actions
39 lines (36 loc) · 953 Bytes
/
KeyListenerDemo.java
File metadata and controls
39 lines (36 loc) · 953 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
39
//java program to demonstrate awt and Key Event Handling
import java.awt.*;
import java.awt.event.*;
public class KeyListenerDemo extends Frame implements KeyListener {
Label l;
TextArea ta;
KeyListenerDemo()
{
l=new Label();
l.setBounds(20, 50, 100, 20);
ta=new TextArea();
ta.setBounds(20, 80, 300, 300);
ta.addKeyListener(this);
add(l);
add(ta);
setSize(400,400);
setLayout(null);
setVisible(true);
}
public void keyPressed(KeyEvent e) {
// TODO Auto-generated method stub
l.setText("Key Pressed");
}
public void keyReleased(KeyEvent arg0) {
// TODO Auto-generated method stub
l.setText("Key Released");
}
public void keyTyped(KeyEvent arg0) {
// TODO Auto-generated method stub
l.setText("Key Typed");
}
public static void main(String[] args) {
// TODO Auto-generated method stub
new KeyListenerDemo();
}
}