Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

Sign up now!

Question Passing UI variables via the controller to other classes.

Joined
Mar 18, 2017
Messages
36
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.
 
Go check out new bots and give helpful feedback.
Joined
Jan 31, 2016
Messages
5,413
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.
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.
 
Top