-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy path_3.KeyEvents.java
More file actions
43 lines (40 loc) · 850 Bytes
/
_3.KeyEvents.java
File metadata and controls
43 lines (40 loc) · 850 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
40
41
42
43
import java.awt.*;
import java.awt.event.*;
public class KeyEvents extends KeyAdapter
{
Label l;
TextArea area;
Frame f;
Main()
{
f = new Frame("Key Adapter");
l = new Label();
l.setBounds(20,50,200,20);
area = new TextArea();
area.setBounds(20,80,300,300);
area.addKeyListener(this);
f.add(l);
f.add(area);
f.setSize(400,400);
f.setLayout(null);
f.setVisible(true);
}
public void keyReleased(KeyEvent e)
{
String text = area.getText();
String words[] = text.split("//s");
l.setText("Words: " + words.length + " Characters:" + text.length());
}
public void keyTyped(KeyEvent e)
{
l.setText("Typing...");
}
public void keyPressed(KeyEvent e)
{
l.setText("Key Pressed..");
}
public static void main (String[] args)
{
new KeyEvents();
}
}