Download Checkbox(String str,Boolean on)

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
A Checkbox is a control that is used
to turn an option on or off.
It consist of a small box that can either contain a check
Marks of not.
There is a Label associated with each check box.
The Checkbox is an object of Checkbox class.
Checkbox() :- It create a checkbox whose
label in blank.
Checkbox(String str) :- It create a checkbox
whose label is
specified by str.
Checkbox(String str,Boolean on) :- It create
a checkbox whose
label is specified by str and
set initial state of the checkbox.
getState() :-It returns the state of the
checkbox.
setState() :- It sets the state of the void
setState(Boolean flag)
getLabel() :- It returns the label of the checkbox.
Sting getLabel().
setLabel() :- It set the label of the checkbox.
void setLabel(String str).
addItemListener() :- It adds the indicates item
listener to the checkbox.
void addItemListener(ItemListener obj)
import java.applet.*;
import java.awt.*;
/*<applet code=check.class width=400 height=400></applet>*/
public class check extends Applet {
Checkbox c1,c2,c3;
public void init()
{
c1=new Checkbox("TV");
c2=new Checkbox("Computer");
c3=new Checkbox("Laptop");
setLayout(new FlowLayout());
add(c1);
add(c2);
add(c3);
}
}
import java.awt.*;
class check extends Frame
{
Checkbox c1,c2,c3;
check(String str)
{
super(str);
c1=new Checkbox("TV");
c2=new Checkbox("Computer");
c3=new Checkbox("Laptop");
setLayout(new FlowLayout());
add(c1);
add(c2);
add(c3);
}
}
class CheckBoxDemo
{
public static void main(String[] args)
{
check ob=new check("Hello");
ob.setTitle("CheckBoxDemo");
ob.setVisible(true);
ob.setSize(350,350);
}
}
A checkbox is selected or deselected
when an ItemEvent is generated.
The ItemListener defines the method
itemStateChange().
void ItemStateChange(ItemEvent ob)
ItemEvent :- It is generated when a checkbox or a listitem
is clicked or menu item is selected or deselected.
getItem() :- It is used to obtain a reference to the item
import java.awt.*;
import java.awt.event.*;
class Check extends Frame implements ItemListener
{
Checkbox c1,c2,c3;
TextField t1;
Check(String str)
{
super(str);
c1=new Checkbox();
c2=new Checkbox("Computer");
c3=new Checkbox("Keyboard");
c1.setLabel("TV");
c1.addItemListener(this);
c2.addItemListener(this);
c3.addItemListener(this);
t1=new TextField(20);
setLayout(new FlowLayout());
add(c1);
add(c2);
add(c3);
add(t1);
}
public void itemStateChanged(ItemEvent ob)
{
String s,str1="";
if(c1.getState()==true)
str1+="TV";
if(c2.getState()==true)
str1+="Computer";
if(c3.getState()==true)
str1+="Laptop";
t1.setText(str1);
}
}
class CheckDemo
{
public static void main(String arg[])
{
Check ob=new Check("Check Demo");
ob.setVisible(true);
ob.setSize(400,400);
}
}