Here, a polyline is used. Seven vertices with xy coordinates, stored in a double array, are sent in the constructor.
This corresponds to 6 lines, with 4 lines (first four lines or first 5 vertices) forming a W line shape.
package ex10;
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.paint.Color;
import javafx.scene.shape.Polyline;
import javafx.stage.Stage;
public class Ex10 extends Application {
@Override
public void start(Stage primaryStage) {
double x = 200, y = 200, w = 100;
double[] vertData = { x-2*w, y-w,
x-w, y+w,
x, y-w,
x+w, y+w,
x+2*w, y-w,
x, 0,
x-2*w, y-w};
Polyline polyline = new Polyline(vertData);
polyline.setFill(Color.rgb(1, 225, 80));
Group root = new Group();
root.getChildren().addAll(polyline);
Scene scene = new Scene(root, 400, 400, Color.PALEGREEN);
primaryStage.setTitle("Example 10. Polyline");
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
This is the output:
No comments:
Post a Comment