-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathItemListenerDemo1.java
More file actions
40 lines (32 loc) · 948 Bytes
/
ItemListenerDemo1.java
File metadata and controls
40 lines (32 loc) · 948 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
import java.awt.*;
import java.awt.event.*;
public class ItemListenerDemo1 implements ItemListener{
Checkbox ch1,ch2,ch3;
Label l1;
public ItemListenerDemo1(){
Frame f = new Frame("CheckBox Example");
l1 = new Label();
l1.setAlignment(Label.CENTER);
l1.setSize(400,100);
ch1 = new Checkbox("Pune");
ch1.setBounds(100,100,50,50);
ch2 = new Checkbox("Mumbai");
ch2.setBounds(100,150,80,50);
f.add(ch1);f.add(ch2);f.add(l1);
ch1.addItemListener(this);
ch2.addItemListener(this);
f.setSize(400,400);
f.setLayout(null);
f.setVisible(true);
}
public void itemStateChanged(ItemEvent e)
{
if(e.getSource()==ch1)
l1.setText("Pune Is "+(e.getStateChange()==1? "Checked " : "Unchecked"));
if(e.getSource() == ch2)
l1.setText("Mumbai Is "+(e.getStateChange() == 1? "checked " : "Unchecked"));
}
public static void main(String[] args) {
new ItemListenerDemo1();
}
}