-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuttonevent.java
More file actions
46 lines (37 loc) · 1005 Bytes
/
buttonevent.java
File metadata and controls
46 lines (37 loc) · 1005 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
44
45
46
import java.awt.*;
import java.awt.event.*;
public class buttonevent extends Frame implements ActionListener {
int num;
Button b1;
TextField t1;
public buttonevent() {
setLayout(new FlowLayout());
b1 = new Button("click me");
t1 = new TextField(20);
add(b1);
add(t1);
b1.addActionListener(this);
}
public void actionPerformed(ActionEvent ae) {
String cmd = ae.getActionCommand();
if (num == 0) {
System.out.println(cmd);
}
if (cmd.equals("click me")) {
num++;
}
if ((num % 2) != 0) {
t1.setText("Hello Buddy!");
}
if ((num % 2) == 0) {
t1.setText(" ");
System.out.println(num);
}
}
public static void main(String args[]) {
buttonevent ob = new buttonevent();
ob.setSize(500, 500);
ob.setVisible(true);
ob.setTitle("button Event Handling");
}
}