我正在尝试创建一个允许用户购买门票和小吃的电影院预订系统,并在每次点击时刷新标签。
我有两节课:
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();
}
}
}
这里奇怪的是,如果我再次单击任何小吃,标签会正确显示所选食物的价格以及所选每个座位的电影价格。
心有法竹
相关分类