下面的代码是一个项目的动作监听器。基本上,我有 4 个单选按钮,当我单击一个时,我希望它更改屏幕上的变量。当我运行代码时,它只是将所有值加在一起。还有其他方法可以做到这一点吗?
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);
}
}
}