폴리라인은 동일한 평면에 존재하는 n개의 선을 사용하여 형성된 열린 도형입니다. 즉, 폴리라인은 닫히지 않은 것을 제외하고는 폴리곤과 동일합니다. JavaFX에서 폴리라인은 javafx.scene.shape.PolyLine으로 표현됩니다. 수업.
폴리곤을 생성하려면 다음을 수행해야 합니다.
-
이 클래스를 인스턴스화하십시오.
-
폴리곤을 생성자에 인수로 전달하거나 getPoints() 메서드를 −
로 사용하여 클래스에 다각형을 그리는 선분의 시작 및 끝점을 전달합니다.
polygon.getPoints().addAll(new Double[]{ List of XY coordinates separated by commas }); -
생성된 노드(모양)를 Group 개체에 추가합니다.
예
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
import javafx.scene.shape.Polyline;
public class DrawingPolyLine extends Application {
public void start(Stage stage) {
//Drawing a polygon
Polyline poliline = new Polyline();
//Setting the properties of the ellipse
poliline.getPoints().addAll(new Double[]{
150.0, 200.0, 410.0, 200.0, 250.0, 50.0, 250.0, 230.0 });
//Setting other properties
poliline.setStrokeWidth(8.0);
poliline.setStroke(Color.DARKSLATEGREY);
//Setting the Scene
Group root = new Group(poliline);
Scene scene = new Scene(root, 595, 300, Color.BEIGE);
stage.setTitle("Drawing Polyline");
stage.setScene(scene);
stage.show();
}
public static void main(String args[]){
launch(args);
}
} 출력
