Monday, April 20, 2009

How to Use CheckBoxGroup

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);
}
}

0 comments:

About This Blog

This Blog is all about Java and programming.This blog is written by Vaibhav Pandey(Read More about him) .He is a Computer Science Graduate .You can contact the author at javatute@gmail.com for any suggestion or Query.You can also contact the author for advertising on this blog.All the material presented here is the property of author and its reproduction in any form is strictly prohibited.

Disclaimer:-Download links provided here are not of author in any means.These are found over the Internet.
Page copy protected against web site content infringement by Copyscape

  © Blogger templates The Professional Template by Ourblogtemplates.com 2008

Back to TOP