implemented the skip btn and that thas the aswer is shown

This commit is contained in:
Jonas Hinterdorfer 2025-05-12 15:19:00 +02:00
parent e3f033d1e5
commit d0f4266f53
2 changed files with 78 additions and 9 deletions

View File

@ -1,4 +1,75 @@
package at.ionas999.questioncatalog.controller; 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 { 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<QuestionCatalog> catalogs;
private ArrayList<Question> 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();
}
} }

View File

@ -1,8 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?> <?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?> <?import javafx.scene.layout.*?>
@ -12,13 +8,15 @@
fx:controller="at.ionas999.questioncatalog.controller.AnswerTextController"> fx:controller="at.ionas999.questioncatalog.controller.AnswerTextController">
<children> <children>
<VBox spacing="20" alignment="CENTER"> <VBox spacing="20" alignment="CENTER">
<Label text="Here goes your question" style="-fx-font-size: 18;"/> <Label fx:id="questionLabel" text="Here goes your question" style="-fx-font-size: 18;"/>
<HBox alignment="CENTER"> <HBox alignment="CENTER">
<TextArea promptText="Type your answer here..." prefHeight="100.0" prefWidth="300.0"/> <TextArea fx:id="textArea" promptText="Type your answer here..." prefHeight="100.0" prefWidth="300.0"/>
</HBox> <Button text="Skip" fx:id="skipBtn" onAction="#onSkipBtnClick"/>
<HBox spacing="10" alignment="CENTER"> <Button text="Show Answer" fx:id="showAnswerBtn" onAction="#onShowAnwerBtnClick"/>
<Button text="Skip"/>
</HBox> </HBox>
</VBox> </VBox>
<HBox alignment="TOP_RIGHT" spacing="10.0" AnchorPane.topAnchor="10.0" AnchorPane.rightAnchor="10.0">
<ComboBox fx:id="selectBox" promptText="Select a Catalog"/>
</HBox>
</children> </children>
</AnchorPane> </AnchorPane>