Create a simple swing applet that demonstrate checkbox and radio button
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
/*
<applet code="box" width=400 height=400>
</applet>
*/
public class box extends JApplet implements ItemListener
{
Container c;
JLabel l1,l2;
JCheckBox c1,c2,c3;
JRadioButton r1,r2,r3;
ButtonGroup bg;
public void init()
{
c=this.getContentPane();
c.setLayout(new FlowLayout());
c1=new JCheckBox("Red");
c.add(c1);
c2=new JCheckBox("Green");
c.add(c2);
c3=new JCheckBox("Blue");
c.add(c3);
l1=new JLabel();
c.add(l1);
c1.addItemListener(this);
c2.addItemListener(this);
c3.addItemListener(this);
l2=new JLabel();
c.add(l2);
r1=new JRadioButton("Red");
c.add(r1);
r2=new JRadioButton("Green");
c.add(r2);
r3=new JRadioButton("Blue");
c.add(r3);
bg=new ButtonGroup();
bg.add(r1);
bg.add(r2);
bg.add(r3);
r1.addItemListener(this);
r2.addItemListener(this);
r3.addItemListener(this);
}
public void itemStateChanged(ItemEvent ie)
{
if(ie.getSource()==c1)
l1.setText("Red is marked");
if(ie.getSource()==c2)
l1.setText("Green is marked");
if(ie.getSource()==c3)
l1.setText("Blue is marked");
if(ie.getSource()==r1)
l2.setText("Red is marked");
if(ie.getSource()==r2)
l2.setText("Green is marked");
if(ie.getSource()==r3)
l2.setText("Blue is marked");
}
}