JavaFX Polygon create from Circle

Description

JavaFX Polygon create from 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.Polygon;
import javafx.stage.Stage;

public class Main extends Application {
  @Override//from  ww  w.java2 s . com
  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);
    
    double length = c.getRadius() / 4;
    Polygon p = new Polygon(c.getCenterX(), c.getCenterY() - length,
      c.getCenterX() - length, c.getCenterY() + length, c.getCenterX() + length, 
      c.getCenterY() + length);
    p.setFill(Color.WHITE);
    p.setStroke(Color.BLACK);

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

    // 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