首页 课程 师资 教程 报名

实现Java单选框的代码

  • 2022-12-30 11:50:34
  • 1738次 动力节点

 实现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();
    }
}

 

选你想看

你适合学Java吗?4大专业测评方法

代码逻辑 吸收能力 技术学习能力 综合素质

先测评确定适合在学习

在线申请免费测试名额
价值1998元实验班免费学
姓名
手机
提交