From d0f4266f5394ecb9a0c57c8a418aae08703655da Mon Sep 17 00:00:00 2001 From: Jonas Hinterdorfer Date: Mon, 12 May 2025 15:19:00 +0200 Subject: [PATCH] implemented the skip btn and that thas the aswer is shown --- .../controller/AnswerTextController.java | 71 +++++++++++++++++++ .../ionas999/questioncatalog/answerText.fxml | 16 ++--- 2 files changed, 78 insertions(+), 9 deletions(-) diff --git a/src/main/java/at/ionas999/questioncatalog/controller/AnswerTextController.java b/src/main/java/at/ionas999/questioncatalog/controller/AnswerTextController.java index ec8894d..3284880 100644 --- a/src/main/java/at/ionas999/questioncatalog/controller/AnswerTextController.java +++ b/src/main/java/at/ionas999/questioncatalog/controller/AnswerTextController.java @@ -1,4 +1,75 @@ package at.ionas999.questioncatalog.controller; +import at.ionas999.questioncatalog.model.Question; +import at.ionas999.questioncatalog.model.QuestionCatalog; +import at.ionas999.questioncatalog.services.QuestionCatalogService; +import at.ionas999.questioncatalog.services.QuestionService; +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; +import javafx.event.ActionEvent; +import javafx.fxml.FXML; +import javafx.scene.control.Button; +import javafx.scene.control.ComboBox; +import javafx.scene.control.Label; +import javafx.scene.control.TextArea; + +import java.sql.SQLException; +import java.util.ArrayList; + public class AnswerTextController { + + @FXML + private ComboBox selectBox; + @FXML + private Button skipBtn; + @FXML + private Button showAnswerBtn; + @FXML + private TextArea textArea; + @FXML + private Label questionLabel; + + private Question currentQuestion = null; + private ObservableList catalogs; + private ArrayList questions; + private int currentIdx = -1; + @FXML + private void initialize() throws SQLException { + this.catalogs = FXCollections.observableList(QuestionCatalogService.GetCatalogsWithoutQuestions()); + selectBox.setItems(catalogs); + addObserverToSelectBox(); + } + private void addObserverToSelectBox() { + selectBox.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> { + if (newValue == null) { + return; + } + + try { + this.questions = QuestionService.GetQuestionsFromCatalog(((QuestionCatalog) newValue).getId()); + this.showNextQuestion(); + + } catch (SQLException e) { + throw new RuntimeException(e); + } + }); + } + + private void showNextQuestion() + { + + this.currentIdx = ++this.currentIdx >= questions.size() ? 0 : this.currentIdx; + + this.currentQuestion = this.questions.get(this.currentIdx); + this.questionLabel.setText(this.currentQuestion.getQuestion()); + } + + @FXML + private void onShowAnwerBtnClick(ActionEvent actionEvent) { + } + + @FXML + private void onSkipBtnClick(ActionEvent actionEvent) { + this.showNextQuestion(); + } } diff --git a/src/main/resources/at/ionas999/questioncatalog/answerText.fxml b/src/main/resources/at/ionas999/questioncatalog/answerText.fxml index 18c7849..966b1b8 100644 --- a/src/main/resources/at/ionas999/questioncatalog/answerText.fxml +++ b/src/main/resources/at/ionas999/questioncatalog/answerText.fxml @@ -1,8 +1,4 @@ - - - - @@ -12,13 +8,15 @@ fx:controller="at.ionas999.questioncatalog.controller.AnswerTextController"> -