1  import javafx.application.Application;
  2  import javafx.scene.Scene;
  3  import javafx.scene.layout.Pane;
  4  import javafx.scene.paint.Color;
  5  import javafx.stage.Stage;
  6  import javafx.scene.shape.Ellipse;
  7  
  8  public class ShowEllipse extends Application {
  9    @Override // Override the start method in the Application class
 10    public void start(Stage primaryStage) {   
 11      // Create a scene and place it in the stage
 12      Scene scene = new Scene(new MyEllipse(), 300, 200);
 13      primaryStage.setTitle("ShowEllipse"); // Set the stage title
 14      primaryStage.setScene(scene); // Place the scene in the stage
 15      primaryStage.show(); // Display the stage
 16    }
 17    
 18    /**
 19     * The main method is only needed for the IDE with limited
 20     * JavaFX support. Not needed for running from the command line.
 21     */
 22    public static void main(String[] args) {
 23      launch(args);
 24    }
 25  }
 26  
 27  class MyEllipse extends Pane {
 28    private void paint() {
 29      getChildren().clear();
 30      for (int i = 0; i < 16; i++) {
 31        // Create an ellipse and add it to pane
 32        Ellipse e1 = new Ellipse(getWidth() / 2, getHeight() / 2, 
 33          getWidth() / 2 - 50, getHeight() / 2 - 50);
 34        e1.setStroke(Color.color(Math.random(), Math.random(),
 35          Math.random()));
 36        e1.setFill(Color.WHITE);
 37        e1.setRotate(i * 180 / 16);
 38        getChildren().add(e1);
 39      }
 40    }
 41    
 42    @Override
 43    public void setWidth(double width) {
 44      super.setWidth(width);
 45      paint();
 46    }
 47    
 48    @Override
 49    public void setHeight(double height) {
 50      super.setHeight(height);
 51      paint();
 52    }
 53  }