0

In my JavaFx Application I need to call a method that is located in the Controller class from a class in the same package. I want to know if this possible to do. I have searched and found somewhat useful stuff but I couldn't figure it out.

I have tried creating an interface with the method that needs to be called and implementing the method in the controller, then using it in the class I need. This does not work and gives errors.

public class Controller implements Initializable {
...
public void doSomething() {
}

}

public class Myclass {
//I need to call the doSomething method here...
}

Any help appreciated! Please ask for more details if situation is unclear.

tcodeb
  • 85
  • 4
  • 11
  • There are dozens of questions on this site that are basically the same as this. You simply need to get a reference to the controller and call the method. (I don't really understand your description of factoring the method to an interface, or why you think that would help.) If you can't get solutions from other similar questions to work, create a [MCVE] and edit your question to include it. – James_D Feb 23 '17 at 00:44
  • I have edited my question but can you explain what you mean by "reference to the controller"? – tcodeb Feb 23 '17 at 00:54
  • @tcodeb [fxmlLLoader.getController()](https://docs.oracle.com/javase/8/javafx/api/javafx/fxml/FXMLLoader.html#getController--) returns a reference to the controller. See the duplicate question or the related [Passing Parameters JavaFX FXML](http://stackoverflow.com/questions/14187963/passing-parameters-javafx-fxml) for further details. – jewelsea Feb 23 '17 at 00:55

0 Answers0