java单选框_java单选框二选一的问题

privateJRadioButtongetJRadioButton1(){if(jRadioButton1==null){jRadioButton1=newJRadioButton();jRadioButton1.setSelected(true);jRadioButton1.setText("\u6309\u7f16\u53f7");...

private JRadioButton getJRadioButton1() {

if(jRadioButton1 == null) {

jRadioButton1 = new JRadioButton();

jRadioButton1.setSelected(true);

jRadioButton1.setText("\u6309 \u7f16 \u53f7");

jRadioButton1.setBounds(340, 115, 74, 23);

}

return jRadioButton1;

}

private JRadioButton getJRadioButton2() {

if(jRadioButton2 == null) {

jRadioButton2 = new JRadioButton();

jRadioButton2.setText("\u6309 \u7247 \u540d");

jRadioButton2.setBounds(340, 137, 74, 23);

}

return jRadioButton2;

}

private JLabel getJLabel2() {

if(jLabel2 == null) {

jLabel2 = new JLabel();

jLabel2.setText("\u63d0\u793a:");

jLabel2.setBounds(340, 442, 44, 15);

}

return jLabel2;

}

private JLabel getJLabel11() {

if(jLabel11 == null) {

jLabel11 = new JLabel();

jLabel11.setText("\u5982\u6240\u67e5\u8be2\u7684\u97f3\u50cf\u5df2\u501f\u51fa\uff0c\u70b9\u51fb\u7ee7\u7eed\uff0c\u6309\u59d3\u540d\u67e5\u627e\u3002");

jLabel11.setBounds(379, 442, 396, 15);

}

return jLabel11;

}

private void jButton2ActionPerformed(ActionEvent evt) {

System.out.println("jButton2.actionPerformed, event="+evt);

//TODO add your code for jButton2.actionPerformed

}

public static void main(String[] args) {

ButtonGroup group = new ButtonGroup ();

group.add(jRadioButton1);

group.add(jRadioButton2);

}

}

运行没有错误但是为什么还是两个选项都能选呢?

展开

表情包
插入表情
评论将由博主筛选后显示,对所有人可见 | 还能输入1000个字符
相关推荐
©️2020 CSDN 皮肤主题: 游动-白 设计师:白松林 返回首页