title: JavaFX pass connection to my second window
body: <p>I need help with this javafx code. How can I pass my connect to my second window. I am not using fxml. </p>
  
  <p>here is my is my connection for my login scene and I want to pass it to my second window. </p>
  
  <pre><code>public class LoginStage extends Application {
      GiantsMainStage giantsM = new GiantsMainStage();
  
      private BorderPane boarderPane;
      private HBox hb, hbs;
      private Connection connect = null;
      private Statement stmt = null;
      private boolean userPass, connected;
  
  
      private TextField dbName, sName;
      private PasswordField password;
      private ComboBox&lt;String&gt; serverType;
  
      private Button loginB, clear;
      public Button clearSAF, search, submit;
      private Label dbNL, sNameL, sPassL;
  
  
      @Override
      public void start(Stage loginStage) {
  
          boarderPane = new BorderPane();
  
          GridPane grid = new GridPane();
          grid.setHgap(10);
          grid.setVgap(12);
  
  
          dbName = new TextField();
          sName = new TextField();
          dbName.setPromptText("enter database name");
          sName.setPromptText("enter server name");
  
          password = new PasswordField();
          password.setPromptText("enter server password");
  
          loginB = new Button("Login");
          clear = new Button("Clear");
          loginB.setPrefWidth(100);
          clear.setPrefWidth(100);
  
  
          clearSAF = new Button("Clear");
  
          loginB.setOnAction((javafx.event.ActionEvent e) -&gt; {
  
             if (connectCheck()) {
                 loginStage.hide();
                 giantsM.start(loginStage);
             }
          });
          Scene scene = new Scene(boarderPane);
  
          loginStage.setTitle("Giants Login");
  
  
      }
  
      public void closeConnection() {
  
          if (connect != null) {
              try {
                  stmt.close();
                  connect.close();
              } catch (SQLException e) {
  
              }
          }
      }
  
      public boolean connectCheck() {
  
          connected = false;
  
          String databaseName = dbName.getText().trim();
          String serverName = sName.getText().trim();
          String sreverpassword = password.getText().trim();
  
          int num = 0;
  
          switch (serverType.getValue()) {
              case "MySQL LOCAL":
                  num = 1;
                  break;
              case "MYSQL REMOTE":
                  num = 2;
                  break;
              case "SQL SERVER LOCAL":
                  num = 3;
                  break;
              case "SQL SERVER":
                  num = 4;
                  break;
              default:
          }
  
          if (connect == null) {
              connect = Connections.getconnect(num, databaseName, serverName, sreverpassword);
          }
  
          if (stmt == null) {
              try {
                  stmt = connect.createStatement();
                  connected = true;
              }
              catch (SQLException e) {
                  Alert notify = new Alert(Alert.AlertType.INFORMATION);
                  notify.setTitle("Blank filed");
                  notify.setHeaderText(null);
                  notify.setContentText("Incorrect login.");
                  connected = false;
              }
          }
          return connected;
      }
  
      private boolean isAllFieldFillup() {
          boolean allInfo;
          if (serverType.getValue().equals("server type") &amp;&amp; dbName.getText().isEmpty()
                  &amp;&amp; sName.getText().isEmpty() &amp;&amp; password.getText().isEmpty()) {
              Alert notify = new Alert(Alert.AlertType.INFORMATION);
              notify.setTitle("Blank filed");
              notify.setHeaderText(null);
              notify.setContentText("You are missing some information.");
              notify.showAndWait();
  
              allInfo = false;
          }
          else {
              allInfo = true;
          }
          return allInfo;
      }
  
      public static void main(String[] args) {
          launch(args);
      }
  }
  </code></pre>
  
  <p>This is the class I want to pass connection to: </p>
  
  <pre><code>public class GiantsMainStage extends Application {
      private Connection connect = null;
      private Statement stmt = null;
  
      @Override
      public void start(Stage mainStage) {
  
          mainPane = new BorderPane();
          MenuBar menuBar = new MenuBar();
  
  
          tableView.getColumns().addAll(rankCol, nameCol, posCol, schoolCol, ageCol, warCol);
  
  
          Scene scene = new Scene(mainPane);
          scene.getStylesheets().add(this.getClass().getResource("style.css").toExternalForm());
          mainStage.setTitle("Giants Database");
          mainStage.setScene(scene);
          mainStage.setResizable(false);
          mainStage.show();
  
          mainPane.setId("mainPane");
          mainGrid.setId("mainGrid");
          separat.setId("separat");
          clearSAF.setId("clearSAF");
  
          clearSAF.setOnAction((javafx.event.ActionEvent e) -&gt; {
              if (!rank.getText().isEmpty() || !fName.getText().isEmpty() || 
                      !position.getText().isEmpty() || !school.getText().isEmpty() || 
                      !age.getText().isEmpty() || !war.getText().isEmpty()) {
              rank.clear();
              fName.clear();
              position.clear();
              school.setText("");
              age.clear();
              war.clear();
              }
          });
  
          if (loginStage.connectCheck()) {
              System.out.println("Still connect");
          }
      }
      public static void main(String[] args) {
          launch(args);
      }
  
  }
  </code></pre>