1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Question Passing UI variables via the controller to other classes.

Discussion in 'Developer Support' started by Muggin, Jun 12, 2018.

  1. Muggin

    Joined:
    Mar 18, 2017
    Messages:
    36
    Likes Received:
    23
    I have my UI built and I am trying to figure out how to pass variables from UI via the controller to other classes. (Ex. I am trying to get a food string from a TextField and use it in my withdrawItems class). My initial approach was to set a global String food; variable in the controller then when the start button is pressed it assigns the food variable from a TextField foodChoice.getText();. Then I pass an instance of the bot main class to my other classes which call bot.controller.getFood() which returns the global food variable in the Controller but this returns null.
    I am aware the proper method has something to do with Platform.invokeLater(); but I am seriously confused on how this works and I have tried doing this in many different places within the controller and main class the following way:

    botPlatform.invokeLater(new Runnable() {
    @Override
    public void run() {
    String food2 = foodChoice.getText();
    setFood(food2);
    }
    });

    Any suggestions or tips on how to accomplish this would be much appreciated.
     
  2. awesome123man

    awesome123man Go check out new bots and give helpful feedback.

    Joined:
    Jan 31, 2016
    Messages:
    5,413
    Likes Received:
    1,662
    So you should just have a setter and getter in your AbstractBot class. You pass in this class to your controller and can use the setter to update the values in your AbstractBot inside the controller using it.
     
    lumb taxi and Serene like this.

Share This Page

Loading...