我的舞台在我的while循环中没有响应

问题描述 投票:0回答:1
    public static void main(String[] args) {
        launch(args);
    }
    public static void menu(Stage stage){
        Scanner input = new Scanner(System.in);
        String option;
        GridPane layout = new GridPane();
        do {
            System.out.println("1.Enter Y to show the Window\n2.Enter N to continue\n3.Enter Q to Quit");
            System.out.print("Enter Option : ");
            option = input.next();
            if(option.equals("Y")) {
                stage.show();
            }

        }while (!option.equals("Q"));
    }
    public void start(Stage stage) {
        stage.setTitle("Window");
        menu(stage);
    }

我打开的窗口标题中没有响应。这有点像我为课程编写的程序中遇到的问题的逻辑

java javafx
1个回答
0
投票

这是因为您没有结束循环,请在显示阶段后添加循环中断:

if(option.equals("Y")) {
  stage.show();
  break;
}
© www.soinside.com 2019 - 2024. All rights reserved.