复选框组件
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(200, 160); setVisible(true); setTitle("复选框的使用"); setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); c.setLayout(new BorderLayout()); c.add(panel1, BorderLayout.NORTH); final JScrollPane scrollPane = new JScrollPane(jt); panel1.add(scrollPane); c.add(panel2, BorderLayout.SOUTH); panel2.add(jc1); jc1.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub if(jc1.isSelected()){ jt.append("复选框1被选中\n"); } } }); panel2.add(jc2); jc2.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub if(jc2.isSelected()){ jt.append("复选框2被选中\n"); } } }); panel2.add(jc3); jc3.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub if(jc3.isSelected()){ jt.append("复选框3被选中\n"); } } }); } public static void main(String[] args) { // TODO Auto-generated method stub new CheckBoxTest(); } }
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步