package com.example.javafxproject;
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Arc;
import javafx.scene.shape.ArcType;
import javafx.scene.shape.Ellipse;
import javafx.scene.shape.Line;
import javafx.stage.Stage;
public class Pole extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) {
Scene scene = new Scene(getPane(), 300, 300);
primaryStage.setScene(scene);
primaryStage.setTitle("显示圆柱");
primaryStage.show();
}
/**返回圆柱面板*/
private Pane getPane() {
Group group = new Group(); //组
Ellipse ellipse = new Ellipse(100, 100, 50, 21); //上边圆
ellipse.setStyle("-fx-stroke: black; -fx-fill: white; "); //黑色画线,白色填充
Arc dashArc = new Arc(100, 200, 50, 21, 0, 180); //下边虚线弧
dashArc.setStyle("-fx-fill: white; -fx-stroke: black;"); //黑色画线,白色填充
dashArc.getStrokeDashArray().addAll(6.0, 21.0); //设置虚线
dashArc.setType(ArcType.OPEN); //设置类型
Arc solidArc = new Arc(100, 200, 50, 21, 180, 180); //下边实线弧
solidArc.setStyle("-fx-fill: white; -fx-stroke: black;");
solidArc.setType(ArcType.OPEN);
Line left = new Line(50, 100, 50, 200); //左边线
Line right = new Line(150, 100, 150, 200); //右边线
group.getChildren().addAll(ellipse, dashArc, solidArc, left, right);
return new BorderPane(group);
}
}
JavaFX、显示圆柱
最新推荐文章于 2022-09-26 23:22:49 发布