implemented the skip btn and that thas the aswer is shown
This commit is contained in:
parent
e3f033d1e5
commit
d0f4266f53
@ -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<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();
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,8 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import java.lang.*?>
|
||||
<?import java.util.*?>
|
||||
<?import javafx.scene.*?>
|
||||
<?import javafx.scene.control.*?>
|
||||
<?import javafx.scene.layout.*?>
|
||||
|
||||
@ -12,13 +8,15 @@
|
||||
fx:controller="at.ionas999.questioncatalog.controller.AnswerTextController">
|
||||
<children>
|
||||
<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">
|
||||
<TextArea promptText="Type your answer here..." prefHeight="100.0" prefWidth="300.0"/>
|
||||
</HBox>
|
||||
<HBox spacing="10" alignment="CENTER">
|
||||
<Button text="Skip"/>
|
||||
<TextArea fx:id="textArea" promptText="Type your answer here..." prefHeight="100.0" prefWidth="300.0"/>
|
||||
<Button text="Skip" fx:id="skipBtn" onAction="#onSkipBtnClick"/>
|
||||
<Button text="Show Answer" fx:id="showAnswerBtn" onAction="#onShowAnwerBtnClick"/>
|
||||
</HBox>
|
||||
</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>
|
||||
</AnchorPane>
|
||||
Loading…
Reference in New Issue
Block a user