Login    New User    Forgot Password    Help      

Check Box

Java Tutorials

Example

// program no 71
// check box
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
/*
<applet code="control4" width=250 height=300>

</applet>
*/
public class control4 extends Applet implements ItemListener
{
String msg="";
Checkbox oracle,access,foxpro,dbase;
CheckboxGroup database;
public void init()
{
database=new CheckboxGroup();
oracle=new Checkbox("Oracle",database,true);
access=new Checkbox("Access",database,false);
foxpro=new Checkbox("Foxpro",database,false);
dbase=new Checkbox("Dbase",database,false);

add(oracle);
add(access);
add(foxpro);
add(dbase);

oracle.addItemListener(this);

access.addItemListener(this);
foxpro.addItemListener(this);
dbase.addItemListener(this);
}

public void itemStateChanged(ItemEvent ie)
{
repaint();
}
public void paint(Graphics g)
{
msg="You selected";
msg=msg+database.getSelectedCheckbox().getLabel();
g.drawString(msg,6,100);
}
}

 

Output

Output in applet

Java Tutorials