Please help me in my case to write a method for launching the opening of the MainApp.java MainApp.java pressing the "OK" button in the UchetUspevaemosti.java UchetUspevaemosti.java program codes:
1) UchetUspevemosti.java:
package ch.makery.address; import java.io.IOException; import ch.makery.address.MainApp; import ch.makery.address.PrepodMainApp; import ch.makery.address.StudentMainApp; import javafx.application.Application; import javafx.fxml.FXMLLoader; import javafx.stage.Stage; import javafx.geometry.Insets; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.ChoiceBox; import javafx.scene.layout.AnchorPane; import javafx.scene.layout.VBox; public class UchetUspevaemosti extends Application { Stage window; Scene scene; Button buttonOk; @Override public void start(Stage primaryStage)throws Exception { window = primaryStage; window.setTitle("Uchet Uspevaemosti Studentov"); buttonOk = new Button("OK"); ChoiceBox<String> choiceBox = new ChoiceBox<>(); //getItems return the Observablelist object wich you can add items to //choiceBox.getItems().add("Methodist"); choiceBox.getItems().addAll("Methodist","Prepod","Student"); //setItems choiceBox.setValue("Methodist"); buttonOk.setOnAction(e-> getChoice(choiceBox)); VBox layout =new VBox(10); layout.setPadding(new Insets (100,125,73,125)); layout.getChildren().addAll(choiceBox,buttonOk); scene = new Scene(layout, 350,250); window.setScene(scene); window.show(); } private Object getChoice(ChoiceBox<String> choiceBox) { String person = choiceBox.getValue(); if (person == "Methodist"){ //zapuskaetsya Metodist; MainApp Metodist = new MainApp(); Metodist.main(new String[] {}); Metodist.showOcenkiOverview(); } return null; } public static void main(String[] args) { launch(args); } } 2) MainApp.java:
package ch.makery.address; import java.io.IOException; import ch.makery.address.model.Ocenki; import ch.makery.address.model.GhurnalOcenok; import ch.makery.address.view.BarChartStatisticController; import javafx.application.Application; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.fxml.FXMLLoader; import javafx.scene.Scene; import javafx.scene.layout.AnchorPane; import javafx.scene.layout.BorderPane; import javafx.stage.Modality; import javafx.stage.Stage; public class MainApp extends Application { private Stage primaryStage; private BorderPane rootLayout; //коллекция private static ObservableList<Ocenki> ocenkiData = FXCollections.observableArrayList(); private static ObservableList<GhurnalOcenok> ghurnalocenokData = FXCollections.observableArrayList(); public static ObservableList<GhurnalOcenok> getGhurnalOcenokList() { return ghurnalocenokData; } public static ObservableList<Ocenki> getOcenkiList() { return ocenkiData; } public MainApp() { // Add some sample data //table } @Override public void start(Stage primaryStage) { this.primaryStage = primaryStage; this.primaryStage.setTitle("TCPP"); initRootLayout(); showOcenkiOverview(); } /** * Initializes the root layout. */ public void initRootLayout() { try { // Load root layout from fxml file. FXMLLoader loader = new FXMLLoader(); loader.setLocation(MainApp.class.getResource("view/RootLayoutMetodist.fxml"));// view/PrepodRootLayout.fxml rootLayout = (BorderPane) loader.load(); // Show the scene containing the root layout. Scene scene = new Scene(rootLayout); primaryStage.setScene(scene); primaryStage.show(); } catch (IOException e) { e.printStackTrace(); } } /** * Shows the person overview inside the root layout. */ public void showOcenkiOverview() { try { // Load person overview. FXMLLoader loader = new FXMLLoader(); loader.setLocation(MainApp.class.getResource("view/MetodistOverview.fxml"));// view/PrepodOverviewController.fxml AnchorPane metodistOverview = (AnchorPane)loader.load(); // Set person overview into the center of root layout. rootLayout.setCenter(metodistOverview); } catch (IOException e) { e.printStackTrace(); } } /** * Returns the main stage. * @return */ public Stage getPrimaryStage() { return primaryStage; } /** * Opens a dialog to show Razmer statistics. */ public void showBarChartStatistic() { try { // Load the fxml file and create a new stage for the popup. FXMLLoader loader = new FXMLLoader(); loader.setLocation(MainApp.class.getResource("view/BarChartStatistic.fxml"));// AnchorPane page = (AnchorPane)loader.load(); Stage dialogStage = new Stage(); dialogStage.setTitle("Razmer(diagonal) Statistics"); dialogStage.initModality(Modality.WINDOW_MODAL); dialogStage.initOwner(primaryStage); Scene scene = new Scene(page); dialogStage.setScene(scene); // Set the persons into the controller. BarChartStatisticController controller = loader.getController(); controller.setOcenkiData( ocenkiData); dialogStage.show(); } catch (IOException e) { e.printStackTrace(); } } /** * Opens a dialog to show Current Ocenki for all school year. */ public void showCurrentOcenkiStudent() { try { // Load the fxml file and create a new stage for the popup. FXMLLoader loader = new FXMLLoader(); loader.setLocation(MainApp.class.getResource("view/Current Ocenki Studenta.fxml"));// AnchorPane page = (AnchorPane)loader.load(); Stage dialogStage = new Stage(); dialogStage.setTitle("Current Ocenki for all learning year"); dialogStage.initModality(Modality.WINDOW_MODAL); dialogStage.initOwner(primaryStage); Scene scene = new Scene(page); dialogStage.setScene(scene); // Set the persons into the controller. //BarChartStatisticController controller = loader.getController(); //controller.setOcenkiData( ghurnalocenokData); dialogStage.show(); } catch (IOException e) { e.printStackTrace(); } } public static void main(String[] args) { launch(args); } }