JavaFX Path create from segments

Description

JavaFX Path create from segments

import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.paint.Color;
import javafx.scene.shape.LineTo;
import javafx.scene.shape.MoveTo;
import javafx.scene.shape.Path;
import javafx.scene.shape.QuadCurveTo;
import javafx.stage.Stage;

public class Main extends Application {

    public static void main(String[] args) {
        Application.launch(args);//from ww w  . j  a  v  a2 s  . 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);

        Path path = new Path();

        MoveTo moveTo = new MoveTo();
        moveTo.setX(50);
        moveTo.setY(50);

        QuadCurveTo quadCurveTo = new QuadCurveTo();
        quadCurveTo.setX(150);
        quadCurveTo.setY(50);
        quadCurveTo.setControlX(100);
        quadCurveTo.setControlY(-50);

        LineTo lineTo1 = new LineTo();
        lineTo1.setX(50);
        lineTo1.setY(50);

        LineTo lineTo2 = new LineTo();
        lineTo2.setX(100);
        lineTo2.setY(175);

        LineTo lineTo3 = new LineTo();
        lineTo3.setX(150);
        lineTo3.setY(50);
        path.getElements().add(moveTo);
        path.getElements().add(quadCurveTo);
        path.getElements().add(lineTo1);
        path.getElements().add(lineTo2);
        path.getElements().add(lineTo3);
        path.setTranslateY(30);
        path.setStrokeWidth(3);
        path.setStroke(Color.BLACK);
        
        root.getChildren().add(path);

        primaryStage.setScene(scene);
        
        primaryStage.show();
    }
}



PreviousNext

Related