首页 > 代码库 > java Swing 之单选按钮和复选按钮的使用
java Swing 之单选按钮和复选按钮的使用
/** * java Swing 单选按钮 * @author gao */ package com.gao; import java.awt.FlowLayout; import javax.swing.ButtonGroup; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JRadioButton; import javax.swing.border.EmptyBorder; public class JRadioButtonDemo extends JFrame { public JRadioButtonDemo(){ this.setTitle("单选按钮的使用"); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setBounds(100, 100, 250, 100); JPanel contentPane=new JPanel(); contentPane.setBorder(new EmptyBorder(5,5,5,5)); this.setContentPane(contentPane); contentPane.setLayout(new FlowLayout(FlowLayout.CENTER,5,5)); JRadioButton randioButton1=new JRadioButton("Java"); JRadioButton randioButton2=new JRadioButton("PHP",true); JRadioButton randioButton3=new JRadioButton("C++"); contentPane.add(randioButton1); contentPane.add(randioButton2); contentPane.add(randioButton3); ButtonGroup group=new ButtonGroup(); group.add(randioButton1); group.add(randioButton2); group.add(randioButton3); this.setVisible(true); } public static void main(String[]args){ JRadioButtonDemo example=new JRadioButtonDemo(); } }
/** * Java Swing 复选框 * @author gao */ package com.gao; import java.awt.FlowLayout; import javax.swing.JCheckBox; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.border.EmptyBorder; public class JCheckBoxDemo extends JFrame{ public JCheckBoxDemo(){ this.setTitle("复选按钮的使用"); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setBounds(100, 100, 250, 100); JPanel contentPane=new JPanel(); contentPane.setBorder(new EmptyBorder(5,5,5,5)); this.setContentPane(contentPane); contentPane.setLayout(new FlowLayout(FlowLayout.CENTER,5,5)); JCheckBox checkBox1=new JCheckBox("Java"); JCheckBox checkBox2=new JCheckBox("PHP",true); JCheckBox checkBox3=new JCheckBox("C++"); contentPane.add(checkBox1); contentPane.add(checkBox2); contentPane.add(checkBox3); this.setVisible(true); } public static void main(String[]args){ JCheckBoxDemo example=new JCheckBoxDemo(); } }
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。