0
我试图制作一个GUI,当您单击两个单选按钮中的一个时,根据您是新客户还是返回客户,它将应用不同的折扣。折扣适用于您可以选择的每个不同选项。我的问题是,每次点击复选框添加选项时,它都会复制折扣。第一次是正确的,但每次点击后,折扣越来越高。这里是我的复选框代码:当我切换JCheckBox时,GUI保持复合折扣
@FXML
void tires(ActionEvent event) {
if(isNewCustomer==true){
tireRotation=tireRotation*(1.0-newCustomerDiscount);
//costLabel.setText("$ " +DF.format(cost));
}else{
tireRotation=tireRotation*(1.0-regularCustomerDiscount);
// costLabel.setText("$ " +DF.format(cost));
}
if(tireBox.isSelected()){
cost+=tireRotation;
costLabel.setText("$ " +DF.format(cost));
} else {
cost =cost-tireRotation;
costLabel.setText("$ " +DF.format(cost));
}
}
这里是我的单选按钮代码:
@FXML
void newCustomer(ActionEvent event) {
if (newCustomer.isSelected()){
isNewCustomer=true;
}
}
任何帮助将不胜感激!
首先,你可以删除'isNewCustomer ==真',只是用'isNewCustomer',因为它是一个'boolean'。其次,如果没有选择新客户,则应设置“isNewCustomer = false”,但我没有看到。第三,你正在压倒'轮胎转动',这是我假设的一个基数。我认为你应该使用一个新变量,'tireRotationCost = tireRotation *(1.0-new/regularCustomerDiscount);'。这样,它不会复合,而是每次都会覆盖成本。 –
可能可以在一个处理两个切换的方法中完成。 – Sedrick