Thursday, July 8, 2010

How to Use CheckBoxGroup  

0 comments

CheckboxGroup class is used to group togather the Checkboxes,from which only one can be selected at a time.
That is exactly one Checkbox in that goup will be "on" else remain "false".By clicking on Checkbox we may "on" or "off" the desired Checkbox.This control is mostly used in making selection ,where exactly one selection is needed form given choices.

more on Checkboxes Visit Checkbox Tutorial
Constructor:-

CheckboxGroup() ---> Creates a new instance of CheckboxGroup.
Important Methods:-

void getSelectedCheckbox() ----> Gets the current choice from this check box group.
void setSelectedCheckbox(Checkbox cb) ----> Turn "on" the specified CheckBox.
How to Use CheckboxGroup:-

Example:-

// test.java

import javax.swing.*;
import java.awt.*;

public class test{
public static void main(String[] args){
JFrame frame = new JFrame("Check Box Frame");
CheckboxGroup cb=new CheckboxGroup();
Checkbox chkop1 = new Checkbox("option1",false,cb);
Checkbox chkop2 = new Checkbox("option2",false,cb);
Checkbox chkop3 = new Checkbox("option3",true,cb);
JPanel panel=new JPanel();
panel.add(chkop1);
panel.add(chkop2);
panel.add(chkop3);
frame.getContentPane().add(panel);
frame.pack();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}

What next?

You can also bookmark this post using your favorite bookmarking service:

Related Posts by Categories



0 comments: to “ How to Use CheckBoxGroup

Extension Factory Builder