Working on a JavaFX application for a school project and struggling mightly with trying to get this to work...
I have JavaFX application that launches a main menu screen. From that screen, there are option buttons to launch other screens that work with my application's various classes. It's the simple, classic CRUD app that all CS students have to do.
My question is, I want to compartmentalize the various CRUD screens into their own JavaFX classes (i.e. create.java, update.java, etc). Then my main JavaFX menu screen would call those classes.
Please note, although these classes are all their own separate JavaFX classes, they should all work together as a SINGLE JavaFX application. In other words, they'll be all working together to update the same object (e.g. a Car object).
I've learned that there should only be ONE JavaFX Application (i.e., the other classes should NOT have "extends Application'). My main menu JavaFX screen should be the only one to have 'extends Application'.
OK here's the code for the Main Menu screen:
public class My_Project02 extends Application {
@Override // Override the start method in the Application class
public void start(Stage primaryStage) {
// Hold two buttons in an HBox
HBox hBox = new HBox();
hBox.setSpacing(10);
hBox.setAlignment(Pos.CENTER);
Button btCreate = new Button("Create");
hBox.getChildren().addAll(btCreate);
// Create and register the handler
btCreate.setOnAction((ActionEvent e) -> {
// ** WHAT DO I PUT HERE TO LAUNCH THE JavaFX CreateStage.JAVA CLASS? **
// I added this line below....
CreateStage createWindow = new CreateStage(destroyerList);
// Now this event handler works
});
// Create a scene and place it in the stage
Scene scene = new Scene(hBox, 300, 50);
primaryStage.setTitle("TITLE"); // Set title
primaryStage.setScene(scene); // Place the scene in the stage
primaryStage.show(); // Display the stage
}
}
/**************************
HERE'S THE CreateStage.JAVA FILE
How do I set this up to get this to work from My_Project02?
**************************/
public class CreateStage {
// Added this line below and now this CreateStage class can be launched from My_Project02 application above
Stage primaryStage = new Stage();
Scene scene = new Scene(new Button("OK"), 200, 250);
primaryStage.setTitle("MyJavaFX"); // Set the stage title
primaryStage.setScene(scene); // Place the scene in the stage
primaryStage.show(); // Display the stage
}
-- END --
Please Help! Thanks much in advance to all who reply.