How to pass a new instance variable to JavaFX Controller using Java 7 -


this question has answer here:

for simplicity have javafx app allows set/get name 2 different classes , display name on scene label. works no problem, can't how pass new instance variable different class "anotherclass" javafx fxml controller?

from fxml controller did following reference new instance variable.

public class fxmldocumentcontroller implements initializable {      @fxml     private label label;      @fxml     private void handlebuttonaction(actionevent event) {         system.out.println("hello ");         variable var = new variable();         baseline base = new baseline();          var.setname("rob");         base.printout(var);        label.settext(base.printout(var));         label.settext(label.gettext() + base.set(var));     }      @override     public void initialize(url url, resourcebundle rb) {         // todo     }      } 

as can see in fxml controller have created 2 instances of 2 classes below handle set/get name

public class baseline {      string printout(variable sg){         system.out.println("my name is: "+ sg.getname());         return sg.getname();     }      string set(variable sg){        sg.setname("bob");         return sg.getname();     }  public class variable {     string name;      public string getname() {         return name;     }      public void setname(string name) {         this.name = name;     }  } 

now here question, anotherclass how can pass new instance javafxml controller?

public class anotherclass { fxmldocumentcontroller newinstance = new  fxmldocumentcontroller();  } 

and how can accept new creation of instance inside fxmldocumentcontroller?

refactor fxmldocumentcontroller stores var mutable field, refactor label-setting code method , add following somewhere in anotherclass:

variable variable = new variable(); variable.setname("test"); this.newinstance.setvariable(variable); 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -