0

您如何查看是否选择了按钮并将其用作二进制值

我有 3 个单选按钮,,,,b1它们都是独立的(不在 a 中b2),我需要当用户点击提交时,我可以将二进制值(如果按下则为 true,如果未按下则为 false)保存到变量中b3ButtonGroup

//Gets details when submit is pressed
submit.addActionListener(new ActionListener()
{
    public void actionPerformed(ActionEvent e)
    {
        String name = t.getText();
        String surname = t1.getText();
        String studentID = t2.getText();
        //Code to place binary values into variables depending on the radio buttons selected
    }
});
4

2 回答 2

2

如果您在谈论 a JRadioButton,您可以使用该isSelected()方法来了解用户是否检查过它。

String name = t.getText();
String surname = t1.getText();
String studentID = t2.getText();
boolean checked = myRadioButton.isSelected();
//...
于 2012-11-09T18:07:10.280 回答
1
boolean button1 = b1.isSelected();
boolean button2 = b2.isSelected();
boolean button3 = b3.isSelected();
于 2012-11-09T17:41:02.087 回答