이것은 경로 요소 입방 곡선을 나타내는 클래스입니다. . 현재 좌표에서 지정된(새) 좌표로 3차 곡선을 그리는 데 도움이 됩니다.
선 경로 요소를 생성하려면 -
-
CubicCurve 인스턴스화 수업.
-
setter 메서드를 사용하거나 생성자로 우회하여 이 클래스의 속성에 값을 설정합니다.
-
Path 클래스를 인스턴스화합니다.
-
getElements()를 사용하여 위에서 생성한 Path의 관찰 가능한 목록 개체를 가져옵니다. 방법.
-
위에서 만든 CubicCurve 추가 add() 를 사용하여 관찰 가능한 목록에 대한 개체 방법.
-
마지막으로 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.CubicCurveTo;
import javafx.scene.shape.LineTo;
import javafx.scene.shape.MoveTo;
import javafx.scene.shape.Path;
import javafx.scene.shape.VLineTo;
public class CubicCurveExample extends Application {
public void start(Stage stage) {
//Creating PathElement objects
MoveTo moveTo = new MoveTo(15, 15);
LineTo line1 = new LineTo(100, 150);
//Instantiating the class CubicCurve
CubicCurveTo cubicCurveTo = new CubicCurveTo();
//Setting properties of the class CubicCurve
cubicCurveTo.setControlX1(400.0f);
cubicCurveTo.setControlY1(40.0f);
cubicCurveTo.setControlX2(175.0f);
cubicCurveTo.setControlY2(250.0f);
cubicCurveTo.setX(500.0f);
cubicCurveTo.setY(150.0f);
//Creating the HLineTo object
VLineTo vLine = new VLineTo();
vLine.setY(80);
//Creating a Path
Path path = new Path();
path.getElements().addAll(moveTo, line1, cubicCurveTo, vLine);
//Setting other properties
path.setStrokeWidth(8.0);
path.setStroke(Color.DARKSLATEGREY);
//Preparing the Stage object
Group root = new Group(path);
Scene scene = new Scene(root, 595, 300, Color.BEIGE);
stage.setTitle("JavaFX Example");
stage.setScene(scene);
stage.show();
}
public static void main(String args[]){
launch(args);
}
} 출력
