网站首页 > 教程分享 正文
弧
以下代码显示如何绘制以50,50为中心,半径为25并从角度45延伸到角度315(270度长)的圆弧。
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.stage.Stage; public class Main extends Application { public static void main(String[] args) { Application.launch(args); } @Override public void start(Stage primaryStage) { primaryStage.setTitle("Text Fonts"); Group g = new Group(); Scene scene = new Scene(g, 550, 250,Color.web("0x0000FF",1.0)); Arc arc = new Arc(); arc.setCenterX(50.0f); arc.setCenterY(50.0f); arc.setRadiusX(25.0f); arc.setRadiusY(25.0f); arc.setStartAngle(45.0f); arc.setLength(270.0f); arc.setType(ArcType.ROUND); g.getChildren().add(arc); primaryStage.setScene(scene); primaryStage.show(); } }
上面的代码生成以下结果。
圆
Circle类创建一个新的圆,其中指定的半径和中心位置以像素为单位。
import javafx.application.Application; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.paint.Color; import javafx.scene.shape.Circle; import javafx.stage.Stage; public class Main extends Application { public static void main(String[] args) { Application.launch(args); } @Override public void start(Stage primaryStage) { primaryStage.setTitle("Text Fonts"); Group root = new Group(); Scene scene = new Scene(root, 550, 250,Color.web("0x0000FF")); Circle circle = new Circle(); circle.setCenterX(100.0f); circle.setCenterY(100.0f); circle.setRadius(50.0f); root.getChildren().add(circle); primaryStage.setScene(scene); primaryStage.show(); } }
上面的代码生成以下结果。
例子
以下代码显示了如何使用Circle构造函数传递半径和中心。
import java.util.List; import javafx.application.Application; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.paint.Color; import javafx.scene.shape.Circle; import javafx.stage.Stage; public class Main extends Application { public static void main(String[] args) { Application.launch(args); } @Override public void start(Stage primaryStage) { primaryStage.setTitle("Title"); final Circle circ = new Circle(40, 40, 30); final Group root = new Group(circ); final Scene scene = new Scene(root, 400, 300); primaryStage.setScene(scene); primaryStage.show(); } }
上面的代码生成以下结果。
例2
圆与DropShadow
import javafx.application.Application; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.effect.DropShadow; import javafx.scene.paint.Color; import javafx.scene.shape.Circle; import javafx.scene.text.Font; import javafx.scene.text.FontWeight; import javafx.scene.text.Text; import javafx.stage.Stage; public class Main extends Application { public static void main(String[] args) { Application.launch(args); } @Override public void start(Stage primaryStage) { primaryStage.setTitle(""); Group root = new Group(); Scene scene = new Scene(root, 300, 250, Color.WHITE); Group g = new Group(); DropShadow ds1 = new DropShadow(); ds1.setOffsetY(4.0); Circle c = new Circle(); c.setEffect(ds1); c.setCenterX(50.0); c.setCenterY(125.0); c.setRadius(30.0); c.setFill(Color.RED); c.setCache(true); g.getChildren().add(c); root.getChildren().add(g); primaryStage.setScene(scene); primaryStage.show(); } }
getBoundsInParent()方法返回节点的边界区域,例如其宽度和高度。
对于高度和宽度的 getBoundsInParent()计算包括节点的实际尺寸加上任何效果,平移和变换。例如,具有阴影效果的形状通过包括阴影增加其宽度。
上面的代码生成以下结果。
猜你喜欢
- 2024-09-29 JavaFX文件选择器(java 文件选择器)
- 2024-09-29 JavaFx 实现按钮防抖和软件重启(Kotlin)
- 2024-09-29 JavaFX学习笔记017(单选按钮和复选框)
- 2024-09-29 JavaFX 折线图(java swing 折线图)
- 2024-09-29 JavaFX学习笔记014(菜单栏)(javafx包含功能)
- 2024-09-29 JavaFX 文本字段(javafx 文本编辑器)
- 2024-09-29 还有用Eclipse的吗?这有一个图形编辑框架,据说很厉害!
- 2024-09-29 JavaFX学习入门篇,想用Java写窗口应用的同学可以看看
- 2024-09-29 JavaFX 滑块(javafx scrollpane)
- 2024-09-29 javafx做的航天事件管理系统(javafx做的航天事件管理系统有哪些)
你 发表评论:
欢迎- 最近发表
- 标签列表
-
- css导航条 (66)
- sqlinsert (63)
- js提交表单 (60)
- param (62)
- parentelement (65)
- jquery分享 (62)
- check约束 (64)
- curl_init (68)
- sql if语句 (69)
- import (66)
- chmod文件夹 (71)
- clearinterval (71)
- pythonrange (62)
- 数组长度 (61)
- javafx (59)
- 全局消息钩子 (64)
- sort排序 (62)
- jdbc (69)
- php网页源码 (59)
- assert h (69)
- httpclientjar (60)
- postgresql conf (59)
- winform开发 (59)
- mysql数字类型 (71)
- drawimage (61)
本文暂时没有评论,来添加一个吧(●'◡'●)