【发布时间】:2019-03-05 15:07:07
【问题描述】:
我正在尝试创建一个电影院预订系统,允许用户购买门票和小吃,并在每次点击时刷新标签。
我有两门课:
public class DashboardUserController{
public Label subtotal;
public static Double subtotalCounter = 0.0;
public static Double filmPrice;
@FXML
public void onWaterBottleClick(){
subtotalCounter = subtotalCounter + 1.50;
orderRecipt = orderRecipt + "Water Bottle 1.50£ \n";
setSubtotal();
}
// and similar methods for each type of snack
public void setSubtotal(){
subtotal.setText(subtotalCounter.toString() + " £");
}
// set the price for each click on the label
public void addTicket() {
System.out.println(subtotalCounter);
subtotalCounter = subtotalCounter + filmPrice;
setSubtotal();
}
}
还有一个扩展了 DashboardUserController 的类
public class TheatresController extends DashboardUserController {
@FXML
private void onClick(MouseEvent event) { //method for selection/deselection of seats
ImageView imageView = (ImageView) event.getSource();
if (imageView.getImage() == redSeat) {
Alert alert = new Alert(Alert.AlertType.CONFIRMATION, "Do you want to proceed with the unbooking?", ButtonType.YES, ButtonType.NO);
if (alert.showAndWait().orElse(ButtonType.NO) == ButtonType.YES) {
imageView.setImage(imageView.getImage() == redSeat ? greenSeat : redSeat);
}
} else {
Alert alert = new Alert(Alert.AlertType.CONFIRMATION, "Do you want to proceed with the booking?", ButtonType.YES, ButtonType.NO);
if (alert.showAndWait().orElse(ButtonType.NO) == ButtonType.YES) {
imageView.setImage(imageView.getImage() == redSeat ? greenSeat : redSeat);
addTicket();
}
}
}
这里奇怪的是,如果我再次点击任何小吃,标签会正确显示所选食物的价格加上所选每个座位的电影价格。
【问题讨论】:
-
请创建一个MCVE。总而言之,它是一个最小(少量代码)完整(完全可运行)可验证(我可以放入我的 IDE 并运行没有错误)示例(重新创建您的问题)。
-
在这里我可以澄清一下,通过重新创建您的问题,我的意思是以最小的方式重写必要的代码,以便堆栈溢出的其他人可以在不需要链接代码的 IDE 中运行您的代码,但是将其嵌入到帖子中,您可以执行此操作,但是如果您发现无法始终如一地重新创建问题,那么将代码缩进 4 个空格,就像您已经完成的那样,那么代码存在更大的问题,我们看不到(我不知道) t 想调试你的整个应用程序)据说也许通过调试器来帮助你找到你想要重新创建的问题
-
不幸的是...
-
@Matt 如果我给你发了一个包含整个代码的链接,你能检查一下吗?
-
@Matt 谢谢。 ufile.io/pt728