JavaFX Ellipse create out of Circle

Description

JavaFX Ellipse create out of Circle

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.scene.shape.Ellipse;
import javafx.stage.Stage;

public class Main extends Application {
  @Override//from  w  ww  . jav a 2 s  . c o m
  public void start(Stage primaryStage) {
    // Create a pane
    Pane pane = new Pane();

    Circle c = new Circle();
    c.setRadius(150);
    c.setStroke(Color.BLACK);
    c.setFill(Color.WHITE);

    Ellipse e = new Ellipse();
    e.setCenterY(c.getRadius() - c.getRadius() / 3);
    e.setRadiusX(c.getRadius() / 4);
    e.setRadiusY(c.getRadius() / 3 - 20);
    e.setStroke(Color.BLACK);
    e.setFill(Color.WHITE);

    // Place nodes in pane
    pane.getChildren().addAll(c, e);

    // Create a scene and place it in the stage
    Scene scene = new Scene(pane, 150, 200);
    primaryStage.setTitle("java2s.com");
    primaryStage.setScene(scene);
    primaryStage.show();
  }
}



PreviousNext

Related