JavaFX Quiz cant fill List

AmsananKING

Mitglied
Ich brauche eure Hilfe,
Ich arbeite schon seit längerem an einem Quiz-Programm. Ich habe hierzu FXML-Datei erstellt um Fragen einzufügen(siehe "Bearbeitung.fxml"). Diese Datei besitzt 5 Text Felder um eine Frage mit vier Antworten zu erstellen. Zusätzlich habe ich einen Submit-Knopf eingefügt um die Werte auszulesen. Diese Werte habe ich dann in der Klasse "Bearbeitungscontoller.class" eingelesen und in einem Objekt der Klasse Question.class eingespeist. Das entstandene Objekt möchte ich pro Knopfdruck in einer Liste einfügen. Diese Liste soll so gefiltert werden, sodass Duplikate entfernt werden.
Könntet ihr mir weiterhelfen?
[CODE title="Bearbeitung.fxml"]<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.paint.*?>
<?import javafx.scene.text.*?>

<VBox maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="800.0" prefWidth="800.0" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="Quiz.Controllers.Bearbeitungscontroller">
<children>
<SplitPane dividerPositions="0.0" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="750.0" prefWidth="800.0">
<items>
<VBox prefHeight="748.0" prefWidth="172.0">
<children>
<Label alignment="CENTER" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="50.0" prefWidth="200.0" text="Fragen">
<font>
<Font name="System Bold" size="31.0" />
</font>
<textFill>
<LinearGradient endX="1.0" endY="1.0">
<stops>
<Stop>
<color>
<Color green="0.37501806020736694" blue="0.9800000190734863" />
</color>
</Stop>
<Stop offset="1.0">
<color>
<Color red="0.8157894611358643" green="0.7780214548110962" blue="0.7780214548110962" />
</color>
</Stop>
</stops>
</LinearGradient>
</textFill>
</Label>
<ListView fx:id="listView" prefHeight="698.0" prefWidth="200.0" />
</children>
</VBox>
<GridPane prefHeight="736.0" prefWidth="592.0">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" maxWidth="550.0" minWidth="10.0" prefWidth="513.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="291.0" minWidth="10.0" prefWidth="79.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<Label text="Antwort B" GridPane.rowIndex="2" GridPane.valignment="TOP">
<font>
<Font name="System Bold" size="31.0" />
</font>
<textFill>
<LinearGradient endX="1.0" endY="1.0">
<stops>
<Stop>
<color>
<Color green="0.5144736766815186" blue="0.6710526347160339" />
</color>
</Stop>
<Stop offset="1.0">
<color>
<Color red="0.7368420958518982" green="0.7197855710983276" blue="0.7197855710983276" />
</color>
</Stop>
</stops>
</LinearGradient>
</textFill>
</Label>
<Label prefHeight="17.0" prefWidth="551.0" text="Antwort A" GridPane.rowIndex="1" GridPane.valignment="TOP">
<font>
<Font name="System Bold" size="31.0" />
</font>
<textFill>
<LinearGradient endX="1.0" endY="1.0">
<stops>
<Stop>
<color>
<Color green="0.5144736766815186" blue="0.6710526347160339" />
</color>
</Stop>
<Stop offset="1.0">
<color>
<Color red="0.7368420958518982" green="0.7197855710983276" blue="0.7197855710983276" />
</color>
</Stop>
</stops>
</LinearGradient>
</textFill>
</Label>
<Label prefHeight="87.0" prefWidth="550.0" text="Frage" GridPane.valignment="TOP">
<font>
<Font name="System Bold" size="31.0" />
</font>
<textFill>
<LinearGradient endX="1.0" endY="1.0">
<stops>
<Stop>
<color>
<Color green="0.5144736766815186" blue="0.6710526347160339" />
</color>
</Stop>
<Stop offset="1.0">
<color>
<Color red="0.7368420958518982" green="0.7197855710983276" blue="0.7197855710983276" />
</color>
</Stop>
</stops>
</LinearGradient>
</textFill>
</Label>
<TextField fx:id="FFeld" prefHeight="62.0" prefWidth="550.0" GridPane.valignment="BOTTOM" />
<Label text="Antwort C" GridPane.rowIndex="3" GridPane.valignment="TOP">
<font>
<Font name="System Bold" size="31.0" />
</font>
<textFill>
<LinearGradient endX="1.0" endY="1.0">
<stops>
<Stop>
<color>
<Color green="0.5144736766815186" blue="0.6710526347160339" />
</color>
</Stop>
<Stop offset="1.0">
<color>
<Color red="0.7368420958518982" green="0.7197855710983276" blue="0.7197855710983276" />
</color>
</Stop>
</stops>
</LinearGradient>
</textFill>
</Label>
<Label text="Antwort D" GridPane.rowIndex="4" GridPane.valignment="TOP">
<font>
<Font name="System Bold" size="31.0" />
</font>
<textFill>
<LinearGradient endX="1.0" endY="1.0">
<stops>
<Stop>
<color>
<Color green="0.5144736766815186" blue="0.6710526347160339" />
</color>
</Stop>
<Stop offset="1.0">
<color>
<Color red="0.7368420958518982" green="0.7197855710983276" blue="0.7197855710983276" />
</color>
</Stop>
</stops>
</LinearGradient>
</textFill>
</Label>
<TextField fx:id="AFeld" layoutX="10.0" layoutY="76.0" prefHeight="84.0" prefWidth="550.0" GridPane.rowIndex="1" GridPane.valignment="BOTTOM" />
<TextField fx:id="BFeld" layoutX="10.0" layoutY="76.0" prefHeight="84.0" prefWidth="550.0" GridPane.rowIndex="2" GridPane.valignment="BOTTOM" />
<TextField fx:id="CFeld" layoutX="10.0" layoutY="43.0" prefHeight="84.0" prefWidth="550.0" GridPane.rowIndex="3" GridPane.valignment="BOTTOM" />
<TextField fx:id="DFeld" layoutX="10.0" layoutY="43.0" prefHeight="84.0" prefWidth="550.0" GridPane.rowIndex="4" GridPane.valignment="BOTTOM" />
<Button fx:id="SubmitFRAGE" mnemonicParsing="false" onAction="#SubmitFrage" text="Submit" GridPane.halignment="CENTER" GridPane.rowIndex="5">
<font>
<Font size="41.0" />
</font>
</Button>
<CheckBox fx:id="CB1" mnemonicParsing="false" prefHeight="48.0" prefWidth="48.0" GridPane.columnIndex="1" GridPane.rowIndex="1" GridPane.valignment="BOTTOM">
<font>
<Font size="36.0" />
</font>
</CheckBox>
<CheckBox fx:id="CB2" mnemonicParsing="false" prefHeight="14.0" prefWidth="42.0" GridPane.columnIndex="1" GridPane.rowIndex="2" GridPane.valignment="BOTTOM">
<font>
<Font size="36.0" />
</font>
</CheckBox>
<CheckBox fx:id="CB3" mnemonicParsing="false" prefHeight="41.0" prefWidth="48.0" GridPane.columnIndex="1" GridPane.rowIndex="3" GridPane.valignment="BOTTOM">
<font>
<Font size="36.0" />
</font>
</CheckBox>
<CheckBox fx:id="CB4" mnemonicParsing="false" prefHeight="40.0" prefWidth="48.0" GridPane.columnIndex="1" GridPane.rowIndex="4" GridPane.valignment="BOTTOM">
<font>
<Font size="36.0" />
</font>
</CheckBox>
</children>
</GridPane>

</items>
</SplitPane>
</children>
</VBox>
[/CODE]
[CODE lang="java" title="Bearbeitungscontroller.java"]package Quiz.Controllers;

import Quiz.FXMLRelated.FXMLoadFile;
import Quiz.FandA.Answer;
import Quiz.FandA.Question;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.CheckBox;
import javafx.scene.control.ListView;
import javafx.scene.control.TextField;
import javafx.scene.effect.ImageInput;
import javafx.scene.image.Image;
import javafx.scene.input.MouseEvent;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Set;

public class Bearbeitungscontroller {
FXMLoadFile loadFile =new FXMLoadFile();

@FXML
TextField AFeld,BFeld,CFeld,DFeld,FFeld;
@FXML
Button SubmitFRAGE;
@FXML
CheckBox CB1,CB2,CB3,CB4;
@FXML
ListView listView;



ArrayList<Question>questions=new ArrayList<>();
public void SubmitFrage(ActionEvent event) throws IOException {
ArrayList<Answer> Answers=new ArrayList<>();
CheckBox[] checkBoxes ={CB1,CB2,CB3,CB4};
String[] AnswerFields={AFeld.getText(),BFeld.getText(),CFeld.getText(),DFeld.getText()};
for (int i = 0; i <AnswerFields.length ; i++) {
Answers.add(new Answer(checkBoxes.isSelected(),AnswerFields));

}
Question question =new Question(FFeld.getText(),Answers);

questionFilter(question);

}


public void ClickFrage(MouseEvent mouseEvent){
System.out.println(listView.getSelectionModel().getSelectedItem());

}
public void questionFilter(Question Frage){
if (questions.isEmpty()){
questions.add(Frage);
System.out.println("Erste Frage wurde eingefügt");
}else {


}
}






}
[/CODE]
[CODE lang="java" title="Answer.class"]public class Answer {
Boolean cboolean;
String Answer;

public Answer(Boolean pCboolean,String pAnswer){
this.cboolean=pCboolean;
this.Answer=pAnswer;
}
}[/CODE]
[CODE lang="java" title="Question.class"]
public class Question {
public String getQuestion() {
return Question;
}

String Question;



ArrayList<Answer> Answers;


public Question(String Question,ArrayList<Answer> pAnswers ){
this.Question=Question;
this.Answers=pAnswers;
}
[/CODE]
 
M

Mart

Gast
du latscht deine Liste durch falls du es nochmal findest brichst du einfach ab ...

falls du keins findest -> ergo am Ende bist fügst du es ein


ich versteh nicht genau dein Problem


Java:
    public void questionFilter(Question Frage){
        if (questions.isEmpty()){
            questions.add(Frage);
            System.out.println("Erste Frage wurde eingefügt");
        }else {


            }
        }
das versteh ich auch nicht ... du hast eine Array List und dieser fügst du nur was hinzu wenn sie leer ist ja gut... dh du hast eine Liste mit maximal 1em Element
 
Zuletzt bearbeitet von einem Moderator:

Ähnliche Java Themen


Oben