@Override
    public void initialize(URL location, ResourceBundle resources) {
        // load the quiz
        for (Question question : quiz.questions) {
            questionsList.getItems().add(question.title);
        }
        populateView();
        questionTextField.setOnKeyReleased(e -> {
            questionsList.getItems().set(currentQuestionIndex, questionTextField.getText());
            quiz.questions.get(currentQuestionIndex).title = questionTextField.getText();
            saved = false;
        });
        newAnswerButton.setOnMouseClicked(e -> {
            quiz.questions.get(currentQuestionIndex).options.add(new Option(""));
            addAnswer(questionsTilePane.getChildren().size());
            saved = false;
        });
        rightAnswerComboBox.setOnAction(e -> {
            if (rightAnswerComboBox.getItems().size() > 0) {
                currentQuestion.answer = rightAnswerComboBox.getSelectionModel().getSelectedIndex();
            }
            saved = false;
        });
        questionsList.setOnMouseClicked(e -> {
            int selectedIndex = questionsList.getSelectionModel().getSelectedIndex();
            if (selectedIndex < quiz.questions.size() && selectedIndex >= 0) {
                currentQuestionIndex = selectedIndex;
                currentQuestion = quiz.questions.get(selectedIndex);
            }
            populateView();
            saved = false;
        });
        newQuestionButton.setOnAction(e -> {
            newQuestion();
            questionsList.getItems().add("");
            currentQuestion = this.quiz.questions.get(currentQuestionIndex);
            populateView();
            saved = false;
        });
        deleteQuestionButton.setOnAction(e -> removeQuestion());
        quizOptionsButton.setOnAction(e -> {
            Stage stage = new Stage();
            Window win = new Window(window.getApp(), stage, "Settings for '" + quiz.name + "'");
            win.openView(new QuizSettingsPopupControl(quiz));
            saved = false;
        });
        maxPointsTextInput.addEventFilter(KeyEvent.KEY_TYPED, e -> {
            if (e.getCharacter().matches("[\\D]")) {
                e.consume();
            }
        });
        maxPointsTextInput.setOnKeyReleased(e -> {
            if (!maxPointsTextInput.getText().isEmpty()) {
                currentQuestion.maxReward = Integer.parseInt(maxPointsTextInput.getText());
            } else {
                currentQuestion.maxReward = 50; // TODO un hardcode this
            }
            saved = false;
        });
        FileMenu.getItems().get(2).setOnAction(e -> {
            if (!saved) {
                askForSave();
                closeApp = false;
            } else {
                window.openView(new ChooseQuizScreenControl(true));
            }
        });
        FileMenu.getItems().get(0).setOnAction(e -> InitSave());
        FileMenu.getItems().get(1).setOnAction(e -> {
            openSaveDialog();
        });
        window.getStage().setOnCloseRequest(e -> {
            if (!saved) {
                e.consume();
                askForSave();
                closeApp = true;
            }
        });
    }
@Override
    public void initialize(URL location, ResourceBundle resources) {
       
        for (Question question : quiz.questions) {
            questionsList.getItems().add(question.title);
        }
        populateView();
        questionTextField.setOnKeyReleased(e -> {
            questionsList.getItems().set(currentQuestionIndex, questionTextField.getText());
            quiz.questions.get(currentQuestionIndex).title = questionTextField.getText();
            saved = false;
        });
        newAnswerButton.setOnMouseClicked(e -> {
            quiz.questions.get(currentQuestionIndex).options.add(new Option(""));
            addAnswer(questionsTilePane.getChildren().size());
            saved = false;
        });
        rightAnswerComboBox.setOnAction(e -> {
            if (rightAnswerComboBox.getItems().size() > 0) {
                currentQuestion.answer = rightAnswerComboBox.getSelectionModel().getSelectedIndex();
            }
            saved = false;
        });
        questionsList.setOnMouseClicked(e -> {
            int selectedIndex = questionsList.getSelectionModel().getSelectedIndex();
            if (selectedIndex < quiz.questions.size() && selectedIndex >= 0) {
                currentQuestionIndex = selectedIndex;
                currentQuestion = quiz.questions.get(selectedIndex);
            }
            populateView();
            saved = false;
        });
        newQuestionButton.setOnAction(e -> {
            newQuestion();
            questionsList.getItems().add("");
            currentQuestion = this.quiz.questions.get(currentQuestionIndex);
            populateView();
            saved = false;
        });
        deleteQuestionButton.setOnAction(e -> removeQuestion());
        quizOptionsButton.setOnAction(e -> {
            Stage stage = new Stage();
            Window win = new Window(window.getApp(), stage, "Settings for '" + quiz.name + "'");
            win.openView(new QuizSettingsPopupControl(quiz));
            saved = false;
        });
        maxPointsTextInput.addEventFilter(KeyEvent.KEY_TYPED, e -> {
            if (e.getCharacter().matches("[\\D]")) {
                e.consume();
            }
        });
        maxPointsTextInput.setOnKeyReleased(e -> {
            if (!maxPointsTextInput.getText().isEmpty()) {
                currentQuestion.maxReward = Integer.parseInt(maxPointsTextInput.getText());
            } else {
                currentQuestion.maxReward = 50;
            }
            saved = false;
        });
        FileMenu.getItems().get(2).setOnAction(e -> {
            if (!saved) {
                askForSave();
                closeApp = false;
            } else {
                window.openView(new ChooseQuizScreenControl(true));
            }
        });
        FileMenu.getItems().get(0).setOnAction(e -> InitSave());
        FileMenu.getItems().get(1).setOnAction(e -> {
            openSaveDialog();
        });
        window.getStage().setOnCloseRequest(e -> {
            if (!saved) {
                e.consume();
                askForSave();
                closeApp = true;
            }
        });
    }
@override public void initialize(url location, resourcebundle resources) { for (question question : quiz.questions) { questionslist.getitems().add(question.title); } populateview(); questiontextfield.setonkeyreleased(e -> { questionslist.getitems().set(currentquestionindex, questiontextfield.gettext()); quiz.questions.get(currentquestionindex).title = questiontextfield.gettext(); saved = false; }); newanswerbutton.setonmouseclicked(e -> { quiz.questions.get(currentquestionindex).options.add(new option("")); addanswer(questionstilepane.getchildren().size()); saved = false; }); rightanswercombobox.setonaction(e -> { if (rightanswercombobox.getitems().size() > 0) { currentquestion.answer = rightanswercombobox.getselectionmodel().getselectedindex(); } saved = false; }); questionslist.setonmouseclicked(e -> { int selectedindex = questionslist.getselectionmodel().getselectedindex(); if (selectedindex < quiz.questions.size() && selectedindex >= 0) { currentquestionindex = selectedindex; currentquestion = quiz.questions.get(selectedindex); } populateview(); saved = false; }); newquestionbutton.setonaction(e -> { newquestion(); questionslist.getitems().add(""); currentquestion = this.quiz.questions.get(currentquestionindex); populateview(); saved = false; }); deletequestionbutton.setonaction(e -> removequestion()); quizoptionsbutton.setonaction(e -> { stage stage = new stage(); window win = new window(window.getapp(), stage, "settings for '" + quiz.name + "'"); win.openview(new quizsettingspopupcontrol(quiz)); saved = false; }); maxpointstextinput.addeventfilter(keyevent.key_typed, e -> { if (e.getcharacter().matches("[\\d]")) { e.consume(); } }); maxpointstextinput.setonkeyreleased(e -> { if (!maxpointstextinput.gettext().isempty()) { currentquestion.maxreward = integer.parseint(maxpointstextinput.gettext()); } else { currentquestion.maxreward = 50; } saved = false; }); filemenu.getitems().get(2).setonaction(e -> { if (!saved) { askforsave(); closeapp = false; } else { window.openview(new choosequizscreencontrol(true)); } }); filemenu.getitems().get(0).setonaction(e -> initsave()); filemenu.getitems().get(1).setonaction(e -> { opensavedialog(); }); window.getstage().setoncloserequest(e -> { if (!saved) { e.consume(); askforsave(); closeapp = true; } }); }