K
K
KiomaruTroy2019-12-12 11:39:52
Java
KiomaruTroy, 2019-12-12 11:39:52

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++;
    }
}

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;
    }

When you click on the Button in the Label, the text is displayed, in theory with the answer text assigned from the textField.
What am I doing wrong?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question