import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import javax.swing.JApplet;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
public class ckbox extends JApplet implements ItemListener {
JLabel msg;
JCheckBox cb,cb1,cb2,cb3;
public void init()
{
Container c = getContentPane();
c.setLayout(new FlowLayout());
msg = new JLabel("you have selected ..");
cb = new JCheckBox("Java");
cb.addItemListener(this);
cb1 = new JCheckBox("Dot Net");
cb1.addItemListener(this);
cb2 = new JCheckBox("XYZ");
cb2.addItemListener(this);
cb3 = new JCheckBox("All");
cb3.addItemListener(this);
add(cb3);
add(cb);
add(cb1);
add(cb2);
add(msg);
}
@Override
public void itemStateChanged(ItemEvent ie)
{
JCheckBox temp = (JCheckBox)ie.getItem();
if(temp.isSelected() == true )
{
msg.setText("you have selected"+temp.getText());
}
else
{
msg.setText("you have deselected"+temp.getText());
}
if(temp.getText().equals("All"))
{
if(temp.isSelected()==true)
{
cb1.setSelected(true);
cb2.setSelected(true);
cb.setSelected(true);
}
else
{
cb1.setSelected(false);
cb2.setSelected(false);
cb.setSelected(false);
}
}
}
}
No comments:
Post a Comment