此代码无法正常工作。当我选择男性时,每次都会自动选择女性?
如何验证单选按钮的性别?
rbtnmale = new JRadioButton("male");
rbtnmale.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
gender="male";
rbtnmale.setSelected(true);
rbtnmale.setSelected(false);
}
});
rbtnmale.setBounds(116, 127, 58, 23);
frame.getContentPane().add(rbtnmale);
rbtnfemale = new JRadioButton("female");
rbtnfemale.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
gender="female";
rbtnfemale.setSelected(true);
rbtnmale.setSelected(false);
}
});
叮当猫咪
相关分类