title: JavaFX - Using Other Classes As Nodes
body: <p>I'm new to JavaFX and am curious about whether or not it is possible to add objects of your own classes as Nodes to a scene in the main start function? For example, I would like to create a root Node in my start function and then add a Button to it. Instead of creating the Button in the same start function, is it possible to instantiate an Object, which creates its own button in its constructor, and then add that to the root Node? Here's what I mean. I have two classes that I'm working with. Main and Bar. Here is my main class:</p>
  
  <pre><code>public class Main extends Application {
  @Override
  public void start(Stage primaryStage) {
      Group root = new Group();
  
      Bar open = new Bar();
  
      root.getChildren().add(open);
  
      Scene scene = new Scene(root, 1024,768, Color.BLACK);
      primaryStage.setScene(scene);
      primaryStage.show();
  }
  
  public static void main(String[] args) {
      launch(args);
  }
  </code></pre>
  
  <p>}</p>
  
  <p>And Here Is My Bar Class:</p>
  
  <pre><code>public class Bar extends BorderPane {
  
  public Bar()
  {
      Button btn = new Button("hey"); 
  }
  </code></pre>
  
  <p>}</p>
  
  <p>When I launch the application, a 1024 X 768 black box open up but there is no Button on it. Why? When I create my Bar object (open), its default constructor creates a Button. That Bar object is then added as one of the children to my root object in main. If my bar object is now one of the root object's children, and the root object is used in the Scene, shouldn't the button from the Bar object's constructor show up when I launch the app?</p>
  
  <p>On a larger scale, is this typically done in Javafx? Having everything in a separate class and keeping the main start function as clean as possible Or is it ok to instantiate various objects in that function? Thanks so much.</p>