JavaFX Path create

Description

JavaFX Path create


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

public class Main extends Application {
  public static void main(String[] args) {
    Application.launch(args);/*from  w  w w  .java 2  s.  c  om*/
  }

  @Override
  public void start(Stage stage) {
    // Create a triangle using a Path         
    Path pathTriangle = new Path(new MoveTo(50, 0), 
            new LineTo(0, 50), 
            new LineTo(100, 50), 
            new LineTo(50, 0)); 

    pathTriangle.setFill(Color.LIGHTGRAY); 
    pathTriangle.setStroke(Color.BLACK); 
    
    // Add all shapes to an HBox
    HBox root = new HBox(pathTriangle);
    root.setSpacing(10);

    Scene scene = new Scene(root);
    stage.setScene(scene);
    stage.setTitle("2D Shapes");
    stage.show();
  }
}



PreviousNext

Related