title: How to add a method to a button to switch between scenes in JavaFX
body: <p>I have created two java classes which have a static method which returns an AnchorPane after setting all properties of required labels and buttons.
  For example:</p>
  
  <pre><code>class HomePageScene {
      static AnchorPane getHomePageScene() {
          //some code
          //a button which is to be clicked to go to Login Page
          //some code
      }
  }
  
  class LoginPageScene {
      static AnchorPane getLoginPageScene() {
          //some code
      }
  }
  </code></pre>
  
  <p>And there is another class which has the <code>main()</code>.</p>
  
  <pre><code>public class JavaFXEventDemo extends Application {
      public static void main(String[] args) {
          launch(args);
      }
      public void start(Stage myStage) {
          myStage.setTitle("Program Windiw");
          AnchorPane HomePane = HomePageScene.getHomePageScene();
          AnchorPane LoginPane = LoginPageScene.getLoginPageScene();
  
          Scene HomePage = new Scene(HomePane, 400.0, 300.0);
          Scene LoginPage = new Scene(LoginPane, 400.0, 300.0);
  
          myStage.setScene(HomePage);
          myStage.show();
      }
  }
  </code></pre>
  
  <p>First I set the HomePage as the scene on the stage. In the screen there is a button, which when I click, I want the scene to the LoginPage. How do I do this?
  All the three classes are in different files.I tried setting onAction() method, but in that, handle() method's return type is void, whereas I need to return an AnchorPane.</p>