标签:
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();//面板
private JPanel panel2=new JPanel();//面板
private JTextArea jt=new JTextArea(3,10);//也是面板通常用于文字
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("复选框案例");
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("复选框第一个被选中\n");
}
}
});
panel2.add(jc2);
jc2.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (jc2.isSelected()) {
jt.append("复选框2被选中\n");
}
}
});
panel2.add(Jc3);
Jc3.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (Jc3.isSelected()) {
jt.append("复选框3被选中");
}
}
})
;
}
public static void main(String[] args) {
new CheckBoxTest();
}
}
标签:
原文地址:http://www.cnblogs.com/douyunqian3520/p/5518234.html