If I have a class with methods:
class Car{
private String engineRPM;
public Car(){}
public String idleEngine(){
if (engineOn()){
engineRPM = getEngineRPM();
}
return engineRPM;
}
}
How do I run the method in a task on a background thread in Main and then take its returned value and update the GUI?
public class Main extends Application {
Car myCar;
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) throws Exception{
FXMLLoader loader = new FXMLLoader(getClass().getResource("fxml/entry.fxml"));
Parent root = loader.load();
this.mainController = (SystemMessage) loader.getController();
primaryStage.setTitle("Car");
primaryStage.setScene(new Scene(root, 300, 275));
primaryStage.show();
//perform background task of class method here
myCar = new Car();
myCar.startEngine();
String RPM = myCar.engineIdle(); //
this.mainController.postMessage(RPM);
}