JavaFX Shape create from Path subtract

Description

JavaFX Shape create from Path subtract

import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.effect.DropShadow;
import javafx.scene.paint.Color;
import javafx.scene.shape.Ellipse;
import javafx.scene.shape.Path;
import javafx.scene.shape.Shape;
import javafx.stage.Stage;

public class Main extends Application {

   public static void main(String[] args) {
      Application.launch(args);/*from  ww  w  . j a  va2s.c  o m*/
   }

   @Override
   public void start(Stage primaryStage) {
      primaryStage.setTitle("java2s.com");
      Group root = new Group();
      Scene scene = new Scene(root, 300, 250, Color.WHITE);

      Ellipse bigCircle = new Ellipse();
      bigCircle.setCenterX(100);
      bigCircle.setCenterY(100);
      bigCircle.setRadiusX(50);
      bigCircle.setRadiusY(75 / 2);

      bigCircle.setStrokeWidth(3);
      bigCircle.setStroke(Color.BLACK);
      bigCircle.setFill(Color.WHITE);

      Ellipse smallCircle = new Ellipse();
      smallCircle.setCenterX(100);
      smallCircle.setCenterY(100);
      smallCircle.setRadiusX(35 / 2);
      smallCircle.setRadiusY(25 / 2);

      Shape donut = Path.subtract(bigCircle, smallCircle);
      donut.setStrokeWidth(1);
      donut.setStroke(Color.BLACK);

      donut.setFill(Color.rgb(255, 200, 0));

      DropShadow dropShadow = new DropShadow();
      dropShadow.setOffsetX(2.0f);
      dropShadow.setOffsetY(2.0f);
      dropShadow.setColor(Color.rgb(50, 50, 50, .588));

      donut.setEffect(dropShadow);

      root.getChildren().add(donut);

      primaryStage.setScene(scene);

      primaryStage.show();
   }
}



PreviousNext

Related