更新时间:2022-12-30 11:50:34 来源:极悦 浏览1283次
实现Java单选框的代码是什么?极悦小编来告诉大家。
public class JButtonDemo02 extends JFrame {
public JButtonDemo02() {
Container container = this.getContentPane();
//将一个图片变为图标
URL resource = JButtonDemo01.class.getResource("tx.jpg");
Icon icon = new ImageIcon(resource);
//单选框
JRadioButton RadioButton1 = new JRadioButton("JRadioButton");
JRadioButton RadioButton2 = new JRadioButton("JRadioButton");
JRadioButton RadioButton3 = new JRadioButton("JRadioButton");
//由于单选框只能选择一个,分组
ButtonGroup group = new ButtonGroup();
group.add(RadioButton1);
group.add(RadioButton2);
group.add(RadioButton3);
container.add(RadioButton1,BorderLayout.CENTER);
container.add(RadioButton2,BorderLayout.NORTH);
container.add(RadioButton3,BorderLayout.SOUTH);
this.setVisible(true);
this.setSize(500,300);
this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
// new JButtonDemo01();
new JButtonDemo02();
}
}
0基础 0学费 15天面授
Java就业班有基础 直达就业
业余时间 高薪转行
Java在职加薪班工作1~3年,加薪神器
工作3~5年,晋升架构
提交申请后,顾问老师会电话与您沟通安排学习