i am trying use the design pattern on my Mediator. In order to have my gui seperated instead of having all components in one class.
And example would be that you needed to be logged into the program before using other GUI components. Therefore creating a Mediator class that creates an instance of each gui element that each of the GUI classes (Login, addUser, ShowUser) could refer to when changeing window.
public class Mediator {
public Login login;
public AddUser add;
public ShowUsers su;
public Stage stage = new Stage();
public Mediator(){
login = new Login(this);
add = new AddUser(this);
su = new ShowUsers(this);
}
public void showUser() throws Exception{
su.start(stage);
}
}
public class ShowUsers extends Application{
private Mediator m;
private Stage stage = new Stage();
public ShowUsers(Mediator m){
this.m =m;
}
@Override
public void start(Stage stage) throws Exception {
Group root = new Group();
Scene scene = new Scene(root);
stage.setScene(scene);
}
}
I am getting an exepction saying:Exception in thread "main" java.lang.IllegalStateException: Not on FX application thread; currentThread = main
How do i get around this if i want to use a mediator?
Update
public class Main {
public static void main(String[] args) throws Exception{
Mediator m = new Mediator();
m.showUser();
}
}
You start a Java FX Application with Application.launch. I don't think you can launch more than one Application per JVM, but I haven't tried (why would you want?). Of course you can have several Stages per application though.
Edit: In fact the Javadoc says: " It must not be called more than once or an exception will be thrown. "
http://docs.oracle.com/javafx/2/api/javafx/application/Application.html#launch(java.lang.String...)