Package com.java.charpter12;
Import Java.awt.BorderLayout;
Import Java.awt.Container;
Import java.awt.event.ActionEvent;
Import Java.awt.event.ActionListener;
Import Javax.swing.JCheckBox;
Import Javax.swing.JFrame;
Import Javax.swing.JPanel;
Import Javax.swing.JScrollPane;
Import Javax.swing.JTextArea;
Import javax.swing.WindowConstants;
public class Checkboxtest extends jframe{
Private static final long serialversionuid=1l;
Private JPanel panel1=new JPanel ();//panel
Private JPanel panel2=new JPanel ();//panel
Private JTextArea jt=new JTextArea (3,10);//The panel is usually used for text
Private Jcheckbox jc1=new Jcheckbox ("1");
Private Jcheckbox jc2=new Jcheckbox ("2");
Private Jcheckbox jc3=new Jcheckbox ("3");
Public Checkboxtest ()
{
Container C=getcontentpane ();
SetSize (300, 400);
Settitle ("check box case");
SetVisible (TRUE);
Setdefaultcloseoperation (Windowconstants.exit_on_close);
C.setlayout (New BorderLayout ());
C.add (Panel1,borderlayout.north);
JScrollPane js=new JScrollPane (JT);//
Panel1.add (JS);
C.add (Panel2,borderlayout.south);
Panel2.add (JC1);
Jc1.addactionlistener (new ActionListener () {
@Override
public void actionperformed (ActionEvent e) {
if (jc1.isselected ()) {
Jt.append ("check box is first selected \ n");
}
}
});
Panel2.add (JC2);
Jc2.addactionlistener (new ActionListener () {
@Override
public void actionperformed (ActionEvent e) {
if (jc2.isselected ()) {
Jt.append ("check box 2 is selected \ n");
}
}
});
Panel2.add (JC3);
Jc3.addactionlistener (new ActionListener () {
@Override
public void actionperformed (ActionEvent e) {
if (jc3.isselected ()) {
Jt.append ("check box 3 is selected");
}
}
})
;
}
public static void Main (string[] args) {
New Checkboxtest ();
}
}
check box component