This is a snippet of my code when I was using Swing:
private static Gui gui;
public static void main(String[] args){
gui = new Gui(); //(1)
gui.menu(); //(2)
gui.show(); //(3)
}
- Constructor initialises
JFrame
- Creates
JLabel
andJPanel
and adds them both into frame. - Set frame visibility to
true
.
I've been trying but I can't get the result I want using Java-FX. This is how my last attempt looked:
private static Gui gui;
public static void main(String[] args){
gui = new Gui();
Application.launch(Gui.class, args);
gui.menu();
gui.show();
}
Gui class:
private static Stage stage;
public class Gui extends Application {
publc void start(Stage primaryStage){
Gui.stage = primaryStage;
stage.setTitle("title");
//I read that some method blocking is involved here, I want to go back!
}
public void menu(){
BorderPane abc = new BorderPane();
Scene scene = new Scene(abc, 200, 200);
stage.setScene(scene);
//if I somehow mange to reach this part, there will be some null pointer
//exception, well everything looks real initialised to me
}
public void show(){
stage.show();
//I have never reach this part
}
}