0
我是新來的人,對編程世界一般,所以請不要恨我。Java:警報窗口不會在「if」語句下打開
我的課剛開始使用「if」語句,出於某種原因,我無法讓我的javafx警報框顯示。也可以打開縮短代碼的任何提示。
public void start(Stage primarystage) {
TextInputDialog getDemNums = new TextInputDialog();
getDemNums.setTitle("How Many?");
getDemNums.setHeaderText("Input number of people desired: ");
Optional<String> sNumber = getDemNums.showAndWait();
int result = Integer.valueOf(sNumber.get());
if(result>=10){
int bigGroup = result/2;
TextInputDialog tenPlus = new TextInputDialog();
tenPlus.setTitle("Group Assignment");
tenPlus.setContentText("The group size is " + bigGroup + " people.");
} else if (result>=3 && result<10) {
int medGroup = result/3;
Alert medWindow = new Alert(AlertType.INFORMATION);
medWindow.setTitle("Group Assignment");
medWindow.setContentText("The group size is " + medGroup + " people.");
} else if(result<3) {
Alert tooSmall = new Alert(AlertType.INFORMATION);
tooSmall.setTitle("ERROR");
tooSmall.setContentText("The number of people has to be at least three");
嘗試'medWindow.showAndWait() '。 – saka1029
您應該使用調試器並逐步執行代碼。查看變量值並查看它爲什麼不落入if語句很容易。 學習如何使用調試器是程序員最有價值的工具之一。 – Nevets17