gpt4 book ai didi

Java - JRadioButton 被选中

转载 作者:行者123 更新时间:2023-12-02 05:13:36 25 4
gpt4 key购买 nike

我有这样的简单检查:

boolean isPressed;


if ((jRadioButton1.isSelected() == false) || (jRadioButton2.isSelected() == false) || (jRadioButton3.isSelected() == false)) {
isPressed = false;
} else {
isPressed = true;
}
System.out.println(isPressed);

为什么我总是得到 false,即使我在面板中标记了 RadioButton?

最佳答案

您的逻辑意味着,如果没有按下任一单选按钮,则 isPressed 为 false。

尝试切换逻辑

if ((jRadioButton1.isSelected() == true) || (jRadioButton2.isSelected() == true) || (jRadioButton3.isSelected() == true)) {
isPressed = true;
} else {
isPressed = false;
}
System.out.println(isPressed);

编辑:可以简化为

isPressed = (jRadioButton1.isSelected() || jRadioButton2.isSelected() || jRadioButton3.isSelected()) 

关于Java - JRadioButton 被选中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27146168/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com