forked from mohammedabdulbari/Java-SE
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CheckboxDemo.java
67 lines (49 loc) · 1.35 KB
/
CheckboxDemo.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package checkboxdemo;
import java.awt.*;
import java.awt.event.*;
class MyFrame extends Frame implements ItemListener
{
Label l;
Checkbox c1,c2,c3;
CheckboxGroup cbg;
public MyFrame()
{
super("Check Box Demo");
l=new Label("Nothing is Selected");
cbg=new CheckboxGroup();
c1=new Checkbox("Java",false,cbg);
c2=new Checkbox("Python",false,cbg);
c3=new Checkbox("C#",false,cbg);
c1.addItemListener(this);
c2.addItemListener(this);
c3.addItemListener(this);
setLayout(new FlowLayout());
add(l);
add(c1);
add(c2);
add(c3);
}
@Override
public void itemStateChanged(ItemEvent e)
{
String str="";
if(c1.getState())
str=str+" "+c1.getLabel();
if(c2.getState())
str=str+" "+c2.getLabel();
if(c3.getState())
str=str+" "+c3.getLabel();
if(str.isEmpty())
str="Nothing is Selected";
l.setText(str);
}
}
public class CheckboxDemo
{
public static void main(String[] args)
{
MyFrame f=new MyFrame();
f.setSize(400,400);
f.setVisible(true);
}
}