TomJ
TomJ

Reputation: 1813

JAVAFX button action to call a function of other class

I am creating a project using javafx. I am using netbeans IDE. I had created many classes. When a button is pressed, a function from other class has to be worked. How to make it working ?

Upvotes: 3

Views: 14444

Answers (1)

assylias
assylias

Reputation: 328568

With Java 8:

button.setOnAction(e -> anInstanceOfYourOtherClass.yourMethod());

Prior to Java 8:

button.setOnAction(new EventHandler<ActionEvent>() {
    @Override public void handle(ActionEvent event) {
        anInstanceOfYourOtherClass.yourMethod();
    }
});

Upvotes: 6

Related Questions