title: JavaFX constructors and changing scene/stage
body: <p>everyone reading</p>
  <p>Currently trying to figure out the basics of JavaFX can somebody help me with how to set a new scene using a constructor from another class. I tried the obvious things to attempt but to no avail except for errors being thrown my way. I guess I just do not understand how to change the stage from my main stage to the classes' stage when choosing a specific menu item. I need to figure this out before attempting any of the actual coding for the classes.</p>
  <p>Thanks for any help!</p>
  <p><strong>Main</strong></p>
  <pre><code>    package application;
  
      import javafx.application.Application;
      import javafx.event.ActionEvent;
      import javafx.event.EventHandler;
      import javafx.scene.Group;
      import javafx.scene.Scene;
      import javafx.scene.control.Button;
      import javafx.scene.control.Label;
      import javafx.scene.control.Menu;
      import javafx.scene.control.MenuBar;
      import javafx.scene.control.MenuItem;
      import javafx.scene.control.TextField;
      import javafx.scene.layout.BorderPane;
      import javafx.scene.layout.HBox;
      import javafx.scene.layout.Pane;
      import javafx.scene.layout.StackPane;
      import javafx.scene.paint.Color;
      import javafx.stage.Stage;
  
      public class Main extends Application implements EventHandler&lt;ActionEvent&gt;
      {
      Pane pane;
      MenuItem item1, item2, item3, item4;
      Label label;
      Scene scene;
      Menu menu;
      
      
     public static void main(String args[]){
        launch(args);
     }
     
      @Override
         public void start(Stage primaryStage) 
         {
             menu = new Menu(&quot;Choose&quot;);
             
             item1 = new MenuItem(&quot;Add Food&quot;);
             item2 = new MenuItem(&quot;Add Exercise&quot;);
             item3 = new MenuItem(&quot;View Log&quot;);
             item4 = new MenuItem(&quot;Exit&quot;);
             
             menu.getItems().addAll(item1, item2, item3, item4);
             
             MenuBar menuBar = new MenuBar(menu);
             menuBar.setTranslateX(200);
             menuBar.setTranslateY(100);
             
             item1.setOnAction(this);
             item2.setOnAction(this);
             item3.setOnAction(this);
             item4.setOnAction(this);
                
             pane = new StackPane();
             
             label = new Label(&quot;Welcome to the Health Tracker!\nWhat would you like to do?&quot;);
             
             pane.getChildren().addAll(label,menuBar);
             scene = new Scene(pane, 400, 400);
             
             primaryStage.setTitle(&quot;Health Tracker&quot;);
             
             primaryStage.setScene(scene);
             primaryStage.show();
         }
   
  
      @Override
      public void handle(ActionEvent event) 
      {
          if(event.getSource() == item1)
          {
              food getfood = new food();
          }
          else if(event.getSource() == item2)
          {
              exercise getExercise = new exercise();
          }
          else if(event.getSource() == item3)
          {
              System.out.print(&quot;log&quot;);
          }
          else if(event.getSource() == item4)
          {
              System.out.print(&quot;exited&quot;);
          }
              
      }
  
      }
  </code></pre>
  <p><strong>Class I am trying to change to</strong></p>
  <pre><code>package application;
  
  import javafx.event.ActionEvent;
  import javafx.event.EventHandler;
  import javafx.scene.Scene;
  import javafx.scene.control.Label;
  import javafx.scene.control.Menu;
  import javafx.scene.control.MenuBar;
  import javafx.scene.control.MenuItem;
  import javafx.scene.layout.Pane;
  import javafx.scene.layout.StackPane;
  import javafx.stage.Stage;
  
  public class food implements EventHandler&lt;ActionEvent&gt;
  {
  Pane pane;
  MenuItem item1, item2;
  Label label;
  Scene scene;
  Menu menu;
  Stage primaryStage;
  
  public void start(Stage primaryStage)
  {
      menu = new Menu(&quot;Choose&quot;);
         
      item1 = new MenuItem(&quot;Add Food&quot;);
      item2 = new MenuItem(&quot;Exit&quot;);
      
      menu.getItems().addAll(item1, item2);
      
      MenuBar menuBar = new MenuBar(menu);
      menuBar.setTranslateX(200);
      menuBar.setTranslateY(100);
      
      item1.setOnAction(this);
      item2.setOnAction(this);
      
      pane = new StackPane();
      
      label = new Label(&quot;Welcome to the Food tracker!\nWhat would you like to do?&quot;);
      
      pane.getChildren().addAll(label,menuBar);
      scene = new Scene(pane, 400, 400);
      
      primaryStage.setTitle(&quot;Food Tracker&quot;);
         
      primaryStage.setScene(scene);
      primaryStage.show();
  }
  
  @Override
  public void handle(ActionEvent event) 
  {
      if(event.getSource() == item1)
      {
          
      }
      if(event.getSource() == item2)
      {
          
      }
      
  }
  
  public food()
  {
      primaryStage.show();
  }
  }
  </code></pre>
  <p>Thanks again for any help :)</p>