i have something like the following:
fxml (view/main/MainMenu.fxml):
<Scene fx:controller="view.main.CtrlMainMenu" xmlns:fx="http://javafx.com/fxml" stylesheets="view/main/main.css">
<GridPane xmlns:fx="http://javafx.com/fxml" alignment="center" id="backgorund" hgap="10" vgap="10">
<!--other panes -->
<VBox spacing="8" GridPane.columnIndex="0" GridPane.rowIndex="1">
<Button text="Start" onAction="#Start"/>
<Button text="Options" onAction="#Options"/>
<Button text="Exit" onAction="#Exit"/>
</VBox>
</GridPane>
</Scene>
main loop (cotroller/main.java):
public class main extends Application{
public static void main(String[] args){
launch(main.class, args);
}
public void start(Stage stage) throws Exception{
stage.setTitle(CtrlLanguage.get(CtrlLanguage.TITLE));
CtrlMainMenu main = new CtrlMainMenu();
Scene scene = main.main(); //don't know how to make Scene scene = (Scene)FXMLLoader.load(getClass().getResource("MainMenu.fxml")); work on here since MainMenu.fxml is in view/main while the main class is in controller and ended up putting CtrlMainMenu in the view although is not very correct
stage.setScene(scene);
stage.setWidth(1080);
stage.setHeight(720);
stage.show();
}
}
view controller (view/main/CtrlMainMenu.java):
public class CtrlMainMenu{
//other buttons actions
public Scene main() throws Exception{
return (Scene)FXMLLoader.load(getClass().getResource("MainMenu.fxml"));
}
@FXML protected void Start(ActionEvent event){
}
@FXML protected void Options(ActionEvent event){
}
@FXML protected void Exit(ActionEvent event){
System.exit(0); //is there any other way to finish the program than using a system.exit?
}
}
got few questions currently:
1. i'd like to be able to keep using CtrlMainMenu for other buttons while the ones that appear there go to the main (since will be reusing those classes from other scenes)
tried adding fx:controller on panes instead of the scene, but it doesnt work at all (it crashes) else directly in CtrlMainMenu change the scenes of the stage, but then, i have to send the stage to every controller i use? (or how do i know the stage of the scene?)
and in the case of options, i'd like after done, go back to the previous scene, is that possible? if so, how?
2.if i want to implement languages, how do i do to change the text? tried with setText() but depending on where do i put it, it crashes, so dont know where do i have to put it
3.im doing a game that may have different number of players, so, is there some way to erase/hide/add data from a gridpane with fxml?