-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcode11.java
51 lines (44 loc) · 1.24 KB
/
code11.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
import java.awt.*;
import java.awt.event.*;
public class code11 extends Frame implements KeyListener {
Label l1, l2, l3;
TextField t1, t2;
TextArea t3;
Button b;
code11() {
// Initialize variables
t1 = new TextField(10);
t2 = new TextField(10);
t3 = new TextArea("ans", 5, 20, TextArea.SCROLLBARS_BOTH);
b = new Button("click me");
l1 = new Label("name");
l2 = new Label("text");
l3 = new Label("event");
// Add components to the frame
add(l1);
add(t1);
add(l2);
add(t2);
add(b);
add(t3);
add(l3);
setLayout(new FlowLayout());
// Add event listeners to components
// b.addActionListener(this);
t1.addKeyListener(this);
t2.addKeyListener(this);
l3.addKeyListener(this);
}
// KeyListener methods
public void keyPressed(KeyEvent ke) {}
public void keyTyped(KeyEvent ke) {}
public void keyReleased(KeyEvent ke) {
String temp = t1.getText();
l3.setText("Length of Name: " + temp.length());
}
public static void main(String[] args) {
code11 f = new code11();
f.setSize(500, 500);
f.setVisible(true);
}
}