title: JavaFX Changing Scene Instead of Stage
body: <p>I'm currently making a program and using JavaFX as the main GUI setting. Currently I'm opening and closing each stage as I go into each different method.</p>
  
  <p>This is a little bit annoying as to the user there are a lot of screens opening and closing when they go through the program.</p>
  
  <p>My question is this, is there a way to instead of opening a stage every time I can move into a different part of my program, I could switch between scenes instead? Would switching between scenes be the correct implementation in this scenario? Would I need to pass a stage between methods?</p>
  
  <p>As you can probably tell I'm just getting started with JavaFX so would appreciate a bit of a lesson.</p>
  
  <p>EDIT: I have decided to update my application using JavaFXML, However I am having difficulties passing a scene into my controller. Here is my Controller;</p>
  
  <pre><code>public class MainApp extends Application {
  
      @FXML
      public Stage primaryStage;
  
      @FXML
      private AnchorPane rootLayout;
  
      @FXML
      private JobInterface jInterface;
  
      @Override
      public void start(Stage primaryStage) {
          primaryStage = new Stage();
          setPrimaryStage(primaryStage);
          initRootLayout();
      }
  
      @FXML
      public void initRootLayout(){
          try {
              primaryStage = getPrimaryStage();
              FXMLLoader loader = new FXMLLoader();
              loader.setLocation(MainApp.class.getResource("MainInterface.fxml"));
              rootLayout = (AnchorPane) loader.load();        
              Scene scene = new Scene(rootLayout);    
              primaryStage.setScene(scene);
              primaryStage.show();
              setPrimaryStage(primaryStage);
           } catch (IOException e) {
                  e.printStackTrace();
           }
      }
  
      @FXML
      private void setJobLayout(){
          primaryStage = getPrimaryStage();
          jInterface = new JobInterface();
          jInterface.initJobLayout();
          primaryStage.setScene(jInterface.getScene());
      }
  
      public static void main(String[] args) {
          launch(args);
      }
  
      public Stage getPrimaryStage() {
          return primaryStage;
      }
  
      public void setPrimaryStage(Stage primaryStage) {
          this.primaryStage = primaryStage;
      }
  }
  </code></pre>
  
  <p>Here is a method that is changing the scene using a different FXML file and attempting to pass the scene back to the controller;</p>
  
  <pre><code>public class JobInterface {
  
      private AnchorPane rootLayout;
      private Scene scene;
  
      public void initJobLayout(){
          try {
              FXMLLoader loader = new FXMLLoader();
              loader.setLocation(MainApp.class.getResource("JobInterface.fxml"));
              rootLayout = (AnchorPane) loader.load();
              scene = new Scene(rootLayout);
              setScene(scene);
          } catch (IOException e) {
              e.printStackTrace();
          }
      }
  
      public Scene getScene() {
          return scene;
      }
  
      public void setScene(Scene scene) {
          this.scene = scene;
      }   
  }
  </code></pre>
  
  <p>The issue I'm having now is a NullPointerException on this line in the main app;</p>
  
  <pre><code>primaryStage.setScene(jInterface.getScene());
  </code></pre>
  
  <p>Any ideas on where I am going wrong?</p>