JavaFX Line create from Ellipse

Description

JavaFX Line create from Ellipse

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

public class Main extends Application {
  @Override//from   w  w w.j  a  v  a2 s . c om
  public void start(Stage primaryStage) {
    // Create a pane
    Pane pane = new Pane();

    // Create an ellipse and set its properties
    Ellipse ellipse = new Ellipse(75, 40, 50, 20);
    ellipse.setStroke(Color.BLACK);
    ellipse.setFill(Color.WHITE);
    ellipse.getStrokeDashArray().addAll(6.0, 21.0);
      
    Line line1 = new Line(ellipse.getCenterX() - ellipse.getRadiusX(), 
                          ellipse.getCenterY(), 
                          ellipse.getCenterX() - ellipse.getRadiusX(),
                          200);
    
    // Place nodes in pane
    pane.getChildren().addAll(ellipse,line1);

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