I am trying to create a game that has two options: that the student can answer a question by introducing the answer or by clicking a button that contains the correct answer. I created the texfield and the buttons for the two types of questions and made if statements that depending on which type of question it is (the type is predetermined) if going to show the buttons or the textfield but it does not work (it does not get into the if). My code looks like this:
SanswerTextField = new TextField();
SanswerTextField.setPrefWidth(300.0);
SanswerTextField.setMinWidth(300.0);
SanswerTextField.setMaxWidth(300.0);
SanswerTextField.setPrefHeight(50.0);
SanswerTextField.setStyle("-fx-font: 30 timesnewroman; -fx-base: #AE3522");
SanswerButton1 = new Button();
SanswerButton1.setPrefWidth(50.0);
SanswerButton1.setMinWidth(50.0);
SanswerButton1.setMaxWidth(50.0);
SanswerButton1.setPrefHeight(50.0);
SanswerButton1.setStyle("-fx-font: 30 timesnewroman; -fx-base: #AE3522");
SanswerButton2 = new Button();
SanswerButton2.setPrefWidth(50.0);
SanswerButton2.setMinWidth(50.0);
SanswerButton2.setMaxWidth(50.0);
SanswerButton2.setPrefHeight(50.0);
SanswerButton2.setStyle("-fx-font: 30 timesnewroman; -fx-base: #AE3522");
SanswerButton3 = new Button();
SanswerButton3.setPrefWidth(50.0);
SanswerButton3.setMinWidth(50.0);
SanswerButton3.setMaxWidth(50.0);
SanswerButton3.setPrefHeight(50.0);
SanswerButton3.setStyle("-fx-font: 30 timesnewroman; -fx-base: #AE3522");
if(saveTypeQ.getText().equals("Choose Answer"))
{
SanswerButton1.setText(saveAnswer.getText());
System.out.println("answer in button: " + SanswerButton1.getText());
SanswerButton2.setText(saveAnswer.getText());
SanswerButton3.setText(saveAnswer.getText());
mathTestButtonPane.add(SanswerButton1,1,4);
mathTestButtonPane.add(SanswerButton2,2,4);
mathTestButtonPane.add(SanswerButton3,3,4);
System.out.println("I am a question to choose an answer");
}
else if(saveTypeQ.getText().equals("Introduce Answer"))
{
mathTestButtonPane.add(SanswerTextField,1,4);
System.out.println("I am a question to introduce an answer");
}
else
{
System.out.println("Not working");
}
it is accessing always the else and I have no idea why. I would really appreciate the help. Thank you in advance.
Aucun commentaire:
Enregistrer un commentaire