Course Hero Logo

Unit 4 java programming ii 21 collected by bipin

Course Hero uses AI to attempt to automatically extract content from documents to surface to you and others so you can study better, e.g., in search results, to enrich docs, and more. This preview shows page 21 - 25 out of 43 pages.

Unit-4/ Java Programming-II21Collectedby Bipin Timalsina
Unit-4/ Java Programming-II22Collectedby Bipin TimalsinaCheckbox GroupIt is possible to create a set of mutually exclusive check boxes in which one and only one checkbox in the group can be checked at any one time. These check boxes are often called radiobuttons, because they act like the station selector on a car radioonly one station can beselected at any one time. For creating a set of mutually exclusive check boxes, we must firstdefine the group to which they will belong and then specify that group when we construct thecheck boxes. Check box groups are objects of typeCheckBoxGroup. Only the defaultconstructor is defined, which creates an empty group.We can determine which check box in a group is currently selected by callinggetSelectedCheckbox( ).We can set a check box by callingsetSelectedCheckbox( ).Thesemethods are as follows:Checkbox getSelectedCheckbox( )void setSelectedCheckbox(Checkbox wh)Here,whis the check box that we want to be selected. The previously selected check box will beturned off.Example: CheckBoxGrouppackage awtexample;import java.awt.*;public class CheckBoxGroupExample{CheckBoxGroupExample(){Frame f= new Frame("CheckboxGroup Example");Label l1 = new Label("Choose your Faculty");l1.setBounds(100,50,200,20);CheckboxGroup cbg = new CheckboxGroup();Checkbox checkBox1 = new Checkbox("BIM", cbg, true);checkBox1.setBounds(100,100, 50,50);Checkbox checkBox2 = new Checkbox("BSc.CSIT", cbg, false);checkBox2.setBounds(100,200, 100,50);Checkbox checkBox3 = new Checkbox("BCA", cbg, false);checkBox3.setBounds(100,300, 50,50);f.add(l1);
Unit-4/ Java Programming-II23Collectedby Bipin Timalsinaf.add(checkBox1); f.add(checkBox2);f.add(checkBox3);f.setSize(500,500);f.setLayout(null);f.setVisible(true);}public static void main(String args[]){new CheckBoxGroupExample();}}
Unit-4/ Java Programming-II24Collectedby Bipin TimalsinaChoice ControlsThe Choice class is used to create a pop -up list of items from which the user may choose. Thus,a Choice control is a form of menu. When inactive, a Choice component takes up only enoughspace to show the currently selected item. When the user clicks on it, the whole list of choicespops up, and a new selection can be made. Each item in the list is a string that appears as a leftjustified label in the order it is added to the Choice object.Choiceonly defines the default constructor, which creates an empty list.In order to add a selection to the list,add( )is used. It has this general form:void add(String name)Here, name is the name of the item being added. Items are added to the list in the order inwhich calls toadd( )occur.In order to determine which item is currently selected, we may call either any of thefollowing methods:String getSelectedItem( )int getSelectedIndex( )ThegetSelectedItem( )method returns a string containing the name of the item.

Upload your study docs or become a

Course Hero member to access this document

Upload your study docs or become a

Course Hero member to access this document

End of preview. Want to read all 43 pages?

Upload your study docs or become a

Course Hero member to access this document

Term
Three
Professor
N/A
Tags

Newly uploaded documents

Show More

Newly uploaded documents

Show More

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture