Home Java Example Java Awt Radio Button In Java



Radio Button In Java
Posted on: March 13, 2008 at 12:00 AM
In this section, you will learn how to create Radio Button on the frame. The java AWT , top-level window, are represent by the CheckBoxGroup. A java program provides you CheckboxGroup.

Radio Button In Java

     

Introduction

In this section, you will learn how to create Radio Button on the frame. The java AWT , top-level window, are represent by the CheckBoxGroup.  A java program provides you CheckboxGroup. In this program, you will see how to create and show the Checkboxgroup component on the frame.

In this program a radio button is created that is an item that can be selected or deselected and displays that state to the user. Here we are creating a group of buttons in which you can select only one option at a time. Here, explanation for the procedure of inserting checkbox group on the Java AWT frame.

Program Description:

Here class named RedioButton, is used in the program for creating a checkboxgroup component. The CheckboxGroup class is  used to set the group together on the checkbox button. A check box group button in a CheckboxGroup can be in the "on" state at any time and pushing any button sets it's state to "on". Clicking any radio button that is in the "off" state turns it into the "on" state.

CheckBoxGroup():  This constructor is used to create a new instance of CheckboxGroup.

Here is the code of  this program:

import java.awt.*;
import java.awt.event.*;
  public class RadioButton{
  public static void main(String[] args) {
  Frame fm=new Frame("RedioButton Group");
  Label la=new Label("What is your choice:");
  fm.setLayout(new GridLayout(01));
  CheckboxGroup cg1=new CheckboxGroup();
  fm.add(la);
  fm.add(new Checkbox("MATH", cg1, true));
  fm.add(new Checkbox("PHYSICS", cg1, false));
  fm.add(new Checkbox("CHEMISTRY", cg1, false));
  fm.add(new Checkbox("ENGLISH", cg1, false));
  fm.setSize(250,200);
  fm.setVisible(true);
  fm.addWindowListener(new WindowAdapter(){
  public void windowClosing(WindowEvent we){
  System.exit(0);
  }
  });
  }
}

Output this program:  

Download this example.

Related Tags for Radio Button In Java:
javaccomideselecttimebuttoninsertcheckboxiouserwindowdisplayvicomponentawtstatethisidradcreatecheckgroupbuttonsframeshowforcteboxprogramnatradiotolearnramoptionlanprocselectedshtopeareilitdesitemproceduresectioncanspluseimceinlevelstamntplaycajispadesexplanationemplanmehowprodocreatingwhichsspcreatedeedisplaysatkishaimellpreeaduandarstatreprrtxpwtvattssrocthtop-levelshoavstatihatdispframkbplprndonlyonomogronl


More Tutorials from this section

Ask Questions?    Discuss: Radio Button In Java   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.