Source of ShowCircleCentered.java


  1: 
  2: import javafx.application.Application;
  3: import javafx.scene.Scene;
  4: import javafx.scene.layout.Pane;
  5: import javafx.scene.paint.Color;
  6: import javafx.scene.shape.Circle;
  7: import javafx.stage.Stage;
  8: 
  9: public class ShowCircleCentered extends Application {
 10:   @Override // Override the start method in the Application class
 11:   public void start(Stage primaryStage) {
 12:     // Create a pane to hold the circle
 13:     Pane pane = new Pane();
 14: 
 15:     // Create a circle and set its properties
 16:     Circle circle = new Circle();
 17:     circle.centerXProperty().bind(pane.widthProperty().divide(2));
 18:     circle.centerYProperty().bind(pane.heightProperty().divide(2));
 19:     circle.setRadius(50);
 20:     circle.setStroke(Color.BLACK);
 21:     circle.setFill(Color.WHITE);
 22:     pane.getChildren().add(circle); // Add circle to the pane
 23: 
 24:     // Create a scene and place it in the stage
 25:     Scene scene = new Scene(pane, 200, 200);
 26:     primaryStage.setTitle("ShowCircleCentered"); // Set the stage title
 27:     primaryStage.setScene(scene); // Place the scene in the stage
 28:     primaryStage.show(); // Display the stage
 29:   }
 30: 
 31:   /**
 32:    * The main method is only needed for the IDE with limited
 33:    * JavaFX support. Not needed for running from the command line.
 34:    */
 35:   public static void main(String[] args) {
 36:     launch(args);
 37:   }
 38: }