Приветствую!
Начал осваивать Java и JavaFX соответственно.
На простом примере покажу всплывшую проблему.
Есть стандартный Controller класс, созданный Java FX и класс ChatBot, к примеру.
Контроллер:
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.*;
public class Controller {
private ChatBot chatBot = new ChatBot();
@FXML Button enterButton;
@FXML TextField answerTextField;
@FXML Label botAnswer;
int counter = 0;
public void button1Click(ActionEvent actionEvent) {
chatBot.setAnswer("[][][]");
botAnswer.setText(chatBot.getChatting(counter));
counter++;
}
}
ChatBot:
public class ChatBot {
String answer;
private String string1 = "Hello!\nI'm intellectual system.\nMy name is... is... my name...\nOh... I forgive it.\n" +
"Starting self-test.\nCore damaged.\nPlease, initialize variable again.\nMy name?";
private String string2 = "Ok, my name is " + answer + ". Please, type date of my creation.";
private String string3 = "My creation date " + answer + "? I'm very young. Thank you. Can you remind me your name?";
private String string4 = "What a great name you have, " + answer + "!\nLet me guess your age.\nEnter remainders of divining your age by 3, 5 and 7.";
String[] chatting = {string1, string2, string3, string4};
public String getChatting(int counter) {
return chatting[counter];
}
public void setAnswer(String answer) {
this.answer = answer;
}
При нажатии на Button в Label выводится текст, по идее с присвоенным из textField текстом answer.
Что я делаю не так?