Переключение между scene - Java
Формулировка задачи:
Помогите, как сделать так чтобы при нажатии на кнопку или menuitem метод stats успешно выполнялся
public class Main extends Application {
private Stage primaryStage;
private BorderPane rootLayout;
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) throws Exception {
this.primaryStage = primaryStage;
this.primaryStage.setTitle("Vs Durak");
this.primaryStage.getIcons().add(new Image("file:res/icon.png"));
initRootLayout();
Menu();
}
private void initRootLayout() {
try {
// Load root layout.
FXMLLoader loader = new FXMLLoader();
loader.setLocation(Main.class.getResource("view/RootLayout.fxml"));
rootLayout = loader.load();
// Show the scene containing the root layout.
Scene scene = new Scene(rootLayout);
primaryStage.setScene(scene);
primaryStage.show();
} catch (IOException e) {
e.printStackTrace();
}
}
protected void Menu() {
try {
// Load menu.
FXMLLoader loader = new FXMLLoader();
loader.setLocation(Main.class.getResource("view/Menu.fxml"));
BorderPane Menu = loader.load();
// Set menu into the center of root layout.
rootLayout.setCenter(Menu);
} catch (IOException e) {
e.printStackTrace();
}
}
protected void Stats() {
try {
// Load statistics.
FXMLLoader loader = new FXMLLoader();
loader.setLocation(Main.class.getResource("view/Stats.fxml"));
BorderPane Stats = loader.load();
// Set statistics into the center of root layout.
rootLayout.setCenter(Stats);
} catch (IOException e) {
e.printStackTrace();
}
}Решение задачи: «Переключение между scene»
textual
Листинг программы
btnOK.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
Stats();
}
});