Hi,
I am new to JavaFX. Though I understand what's happening in the following code, one thing baffles me.
The method getHBox() is referenced from start() method without any object creation. How can a
non-static method be invoked this way?
public class Main extends Application {
@Override
public void start(Stage primaryStage) {
try {
BorderPane rootPane = new BorderPane();
rootPane.setTop(getHBox());
Scene scene = new Scene(rootPane,400,400);
scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
primaryStage.setScene(scene);
primaryStage.show();
} catch(Exception e) {
e.printStackTrace();
}
}
public HBox getHBox()
{
HBox hb = new HBox(15);
hb.getChildren().add(new Button("Press"));
return hb;
}
public static void main(String[] args) {
launch(args);
}
}
If I do something like this, i.e. create an object and then call objectName.getHBox(), the exact same results
obtained:
Main m = new Main();
rootPane.setTop(m.getHBox());
What is going on in these two cases?
Bye.