📅  最后修改于: 2020-10-14 01:11:50             🧑  作者: Mango
通常,椭圆可以定义为具有两个焦点的几何结构。选择椭圆中的焦点,以便到椭圆的每个点到焦点的距离之和是恒定的。
在JavaFX中,类javafx.scene.shape.Ellipse表示Ellipse。需要实例化此类以创建椭圆。此类包含各种属性,需要设置这些属性才能在XY位置上渲染椭圆。
Property | Description | Setter Methods |
---|---|---|
CenterX | Horizontal position of the centre of eclipse | setCenterX(Double X-value) |
CenterY | Vertical position of the centre of eclipse | setCenterY(Double Y-value) |
RadiousX | Width of Eclipse | setRadiusX(Double X-Radious Vaue) |
RadiousY | Height of Eclipse | setRadiusY(Double Y-Radious Value) |
创建椭圆需要遵循三个主要步骤
package application;
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.paint.Color;
import javafx.scene.shape.Ellipse;
import javafx.stage.Stage;
public class Shape_Example extends Application{
@Override
public void start(Stage primaryStage) throws Exception {
// TODO Auto-generated method stub
primaryStage.setTitle("Ellipse Example");
Group group = new Group();
Ellipse elipse = new Ellipse();
elipse.setCenterX(100);
elipse.setCenterY(100);
elipse.setRadiusX(50);
elipse.setRadiusY(80);
group.getChildren().addAll(elipse);
Scene scene = new Scene(group,200,300,Color.GRAY);
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
输出: