Đây là lớp đại diện cho phần tử đường dẫn arc . Nó giúp bạn vẽ một cung tròn từ tọa độ hiện tại đến tọa độ được chỉ định (mới).
Để tạo phần tử đường dẫn dòng -
-
Khởi tạo ArcTo lớp học.
-
Đặt giá trị cho các thuộc tính của lớp này bằng cách sử dụng các phương thức setter hoặc bỏ qua chúng cho hàm tạo.
-
Khởi tạo lớp Path.
-
Nhận đối tượng danh sách có thể quan sát của Đường dẫn được tạo ở trên bằng cách sử dụng getElements () phương pháp.
-
Thêm đối tượng ArcTo đã tạo ở trên vào danh sách có thể quan sát bằng cách sử dụng add () phương pháp.
-
Cuối cùng, thêm đường dẫn đến đối tượng Nhóm.
Ví dụ
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.ArcTo; import javafx.scene.shape.LineTo; import javafx.scene.shape.MoveTo; import javafx.scene.shape.Path; import javafx.scene.shape.VLineTo; public class ArcToExample extends Application { public void start(Stage stage) { //Creating PathElement objects MoveTo moveTo = new MoveTo(490, 50); LineTo line1 = new LineTo(250, 250); //Instantiating the arcTo class ArcTo arcTo = new ArcTo(); arcTo.setX(300.0); arcTo.setY(50.0); arcTo.setRadiusX(50.0); arcTo.setRadiusY(50.0); //Creating the HLineTo object VLineTo vLine = new VLineTo(); vLine.setY(180); //Creating a Path Path path = new Path(); path.getElements().addAll(moveTo, line1, arcTo, 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); } }
Đầu ra