title: How do i make my counter appear in my application through javaFX
body: <p>I'm new to javaFX and I wanted to make a simple code that counted how many times a person pressed a button and displayed the count on the application itself. Currently I have my code printing the counter in my IDE and would just like to some how attach it to the scene(eg I click run and every time I click the button it prints how many times I've clicked it in my workbench). I looked around stack overflow and youtube but the closest I got to what I was looking for was printing it in my IDE. Thanks for any help.</p>
  
  <pre><code>import javafx.application.Application;
  import javafx.scene.Scene;
  import javafx.scene.control.Button;
  import javafx.scene.layout.HBox;
  import javafx.scene.layout.Pane;
  import javafx.scene.paint.Color;
  import javafx.stage.Stage;
  
  
  public class JavaFXTest extends Application {
      private int counter = 0;
  
  
      public static void main (String [] args){
          Application.launch();
      }
  
      @Override
      public void start(Stage primaryStage) throws Exception {
          Stage stage = new Stage();
          stage = primaryStage;
  
          Pane pane = new Pane();
          pane.setPrefSize(400,400);
  
          Button button = new Button("Smash it!");
          HBox root = new HBox(5, pane);
  
          button.setOnAction(e -&gt; {
              counter();
          });
          root.getChildren().add(button);
  
          Scene scene1 = new Scene(root,1000, 800, Color.AQUA);
          stage.setScene(scene1);
          stage.setTitle("ButtonSmash!");
          stage.show();
  
  
      }
  
  
      public void counter(){
          counter++;
          System.out.println(counter);
  
      }
  }
  </code></pre>