以下代码是项目的操作侦听器。基本上,我有4个单选按钮,当我点击一个按钮时,我希望它在屏幕上更改一个变量。当我运行代码时,它只是将所有值加在一起。有没有其他方法可以做到这一点?Action Listener
class Calc implements ActionListener
{
public void actionPerformed(ActionEvent event)
{
double base = 0.00;
double options;
double total;
if (Button25.isSelected());
{
base = base + 999.99;
String base2 = Double.toString(base);
lblBaseAns.setText(base2);
}
if (Button32.isSelected());
{
base = base + 1049.99;
String base2 = Double.toString(base);
lblBaseAns.setText(base2);
}
if (Button35.isSelected());
{
base = base + 1099.99;
String base2 = Double.toString(base);
lblBaseAns.setText(base2);
}
if (Button42.isSelected());
{
base = base + 1155.99;
String base2 = Double.toString(base);
lblBaseAns.setText(base2);
}
}
}
”*将所有值加在一起*“。怎么样? – Lion 2012-04-12 02:27:58
我不知道为什么,但是当我做一个触发代码的动作时,它会将每个单选按钮的所有值加在一起并显示出来。 – Brandon 2012-04-12 02:29:08
这不应该发生。你可能错过了**组**。 – Lion 2012-04-12 02:31:07