用javafx画一个图案:圆形的线宽=5,填充颜色是红色,线条颜色是绿色;弧形的线宽=6,线条颜色是蓝色;长方形的线宽=6,线条颜色是黑色,四个角是圆角;弧形的两端紧贴着长方形的长边的两端。
时间: 2024-02-13 11:06:26 浏览: 169
好的,以下是JavaFX代码:
```
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.paint.Color;
import javafx.scene.shape.Arc;
import javafx.scene.shape.ArcType;
import javafx.scene.shape.Rectangle;
import javafx.scene.shape.StrokeLineCap;
import javafx.scene.shape.StrokeType;
import javafx.stage.Stage;
public class DrawPattern extends Application {
@Override
public void start(Stage primaryStage) {
Group root = new Group();
Scene scene = new Scene(root, 400, 400);
// 画圆形
javafx.scene.shape.Circle circle = new javafx.scene.shape.Circle(150, 150, 100);
circle.setStroke(Color.GREEN);
circle.setStrokeWidth(5);
circle.setFill(Color.RED);
root.getChildren().add(circle);
// 画弧形
Arc arc = new Arc(250, 150, 100, 100, 45, 270);
arc.setType(ArcType.OPEN);
arc.setStroke(Color.BLUE);
arc.setStrokeWidth(6);
arc.setStrokeLineCap(StrokeLineCap.ROUND);
arc.setFill(null);
root.getChildren().add(arc);
// 画长方形
Rectangle rectangle = new Rectangle(100, 200, 200, 100);
rectangle.setArcWidth(20);
rectangle.setArcHeight(20);
rectangle.setStroke(Color.BLACK);
rectangle.setStrokeWidth(6);
rectangle.setStrokeType(StrokeType.CENTERED);
rectangle.setFill(null);
root.getChildren().add(rectangle);
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
```
运行后,会在窗口中画出一个符合要求的图案。
阅读全文
相关推荐
![application/x-zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)