The Controller
In the view we references a controller class hello.Controller
. Now it is time to implement that class. Any class can
be a controller for an FXML view - there is no need to subclass any class or implement a certain Interface. What does our controller need to satisfy the needs of the view? We referenced a function called helloClicked
in the view,
so we implement it and that will be enough. The controller class is instantiated automatically when loading the view so
there is no need to concern ourselves with that.
Create the controller class in src/main/java/hello/Controller.java
:
package hello;
public class Controller {
public void helloClicked() {
System.out.println("Hello!");
}
}
What's happening here
We created a most basic class that has a public function called helloClicked
. This function just prints some
text to the console.
The project is now complete, see the next section for instructions on how to run the project.