0% found this document useful (0 votes)
9 views4 pages

2023 09 11 AWT CheckBoxGroup

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views4 pages

2023 09 11 AWT CheckBoxGroup

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

11/09/2013

CheckboxGroup Class
The object of CheckboxGroup class is used to group together a set of Checkbox.

At a time only one check box button is allowed to be in "on" state and remaining check box
button in "off" state.

Note: CheckboxGroup enables you to create radio buttons in AWT.


There is no special control for creating radio buttons in AWT.

CheckboxGroup Examples
F:\Advanced Java Training Aug2023\Programs\2023-09-
11\CheckBoxGroup1.java
1 import java.awt.*;
2
3
4 public class CheckBoxGroup1
5 {
6
7 CheckBoxGroup1()
8 {
9 Frame f = new Frame("Check Box Example 1 ");
10 CheckboxGroup cbg=new CheckboxGroup();
11
12 Checkbox c1= new Checkbox("Advanced Java", cbg ,
false);
13 c1.setBounds(100,50,100,50);
14 f.add(c1);
15
16
17 Checkbox c2= new Checkbox("Python" , cbg , false);
18 c2.setBounds(100,100,100,50);
19 f.add(c2);
20
21
22 f.setSize(500,500);
23 f.setLayout(null);
24 f.setVisible(true);
25
26 }
27
28
29 public static void main(String args[])
30 {
31 CheckBoxGroup1 myobj= new CheckBoxGroup1();
32 }
33 }
Output :
F:\Advanced Java Training Aug2023\Programs\2023-09-
11\CheckBoxGroupItemListener.java
1 // CheckBoxGroup with Item Listener
2 import java.awt.*;
3 import java.awt.event.*;
4
5 public class CheckBoxGroupItemListener
6 {
7 CheckBoxGroupItemListener()
8 {
9 Frame f = new Frame ("CheckBoxGroup with Item
Listener");
10 CheckboxGroup cbg=new CheckboxGroup();
11
12 Label l1=new Label();
13 l1.setBounds(100,200,200,50);
14 f.add(l1);
15
16
17 Checkbox c1= new Checkbox("Advanced Java", cbg ,
false);
18 c1.setBounds(100,50,100,50);
19 f.add(c1);
20
21
22 Checkbox c2= new Checkbox("Python" , cbg , false);
23 c2.setBounds(100,100,100,50);
24 f.add(c2);
25
26
27 f.setSize(500,500);
28 f.setLayout(null);
29 f.setVisible(true);
30
31 ItemListener c1_listener=new ItemListener(){
32
33 public void itemStateChanged(ItemEvent e){
34 l1.setText("Advanced Java Cheked ");
35 }
36
37 };
38
39 c1.addItemListener(c1_listener);
40
41
42
43 ItemListener c2_listener=new ItemListener(){
44
45 public void itemStateChanged(ItemEvent e){
46 l1.setText("Python Cheked ");
47 }
48
49 };
50
51 c2.addItemListener(c2_listener);
52
53 }
54
55 public static void main(String args[])
56
57 {
58 CheckBoxGroupItemListener obj= new
CheckBoxGroupItemListener();
59
60 }
61 }
62

Output :

You might also like