Answer the question
In order to leave comments, you need to log in
How to pull assign variable from another class in JavaFX?
Greetings!
Started learning Java and JavaFX respectively.
Let me show you the problem with a simple example.
There is a standard Controller class created by Java FX and a ChatBot class for example.
Controller:
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++;
}
}
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;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question