如何在JavaFX中建立弧形?
一般來說,弧形是曲線的一小段。在JavaFX中,它由javafx.scene.shape.Arc類表示。這個類包含六個屬性:
centerX - 此屬性表示弧形中心的x座標。可以使用setCenterX()方法設定此屬性的值。
centerY - 此屬性表示弧形中心的y座標。可以使用setCenterY()方法設定此屬性的值。
radiusX - 此屬性表示當前弧形所屬的完整橢圓的寬度。可以使用setRadiusX()方法設定此屬性的值。
radiusY - 此屬性表示當前弧形所屬的完整橢圓的高度。可以使用setRadiusY()方法設定此屬性的值。
startAngle - 此屬性表示弧形的起始角度(以度為單位)。可以使用setStartAngle()方法設定此屬性的值。
length - 此屬性表示弧形的角度範圍(以度為單位)。可以使用setLength()方法設定此屬性的值。
要建立一個圓圈,你需要:
例項化此類。
使用setter方法設定所需屬性,或者將它們作為引數傳遞給建構函式。
將建立的節點(形狀)新增到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.Arc;
import javafx.scene.shape.ArcType;
public class DrawingArc extends Application {
public void start(Stage stage) {
//Drawing a cubic curve
Arc arc = new Arc();
//Setting properties to cubic curve
arc.setCenterX(280);
arc.setCenterY(230);
arc.setRadiusX(100);
arc.setRadiusY(180);
arc.setStartAngle(45);
arc.setLength(100);
arc.setType(ArcType.ROUND);
//Setting other properties
arc.setFill(Color.CHOCOLATE);
arc.setStrokeWidth(8.0);
arc.setStroke(Color.BROWN);
//Setting the scene object
Group root = new Group(arc);
Scene scene = new Scene(root, 595, 300, Color.BEIGE);
stage.setTitle("Drawing arc");
stage.setScene(scene);
stage.show();
}
public static void main(String args[]){
launch(args);
}
}輸出

廣告
資料結構
網路
關係資料庫管理系統(RDBMS)
作業系統
Java
iOS
HTML
CSS
Android
Python
C語言程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP