我正在尝试创建一个有两个选项的游戏:学生可以通过引入答案或单击包含正确答案的按钮来回答问题。我为两种类型的问题创建了texfield和按钮,并且如果要显示按钮或文本字段但是它不起作用,则根据问题的类型(类型是预定的)制作if语句(它不是进入if)。 我的代码如下所示:
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");
}
它总是访问其他人,我不知道为什么。我真的很感激帮助。提前谢谢。