【JAVA】java单选框二选一的问题
privateJRadioButtongetJRadioButton1(){if(jRadioButton1==null){jRadioButton1=newJRadio...
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);
}
}
运行没有错误但是为什么还是两个选项都能选呢? 展开
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);
}
}
运行没有错误但是为什么还是两个选项都能选呢? 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询