弧形
以下代码显示如何绘制以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
// from =>w WW . y II B AI.c O M
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
// from =>w W W . y ii b AI.c o M
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()
计算包括节点的实际尺寸,高度,宽度,效果,平移和变换。例如,具有阴影效果的形状通过包括阴影增加其宽度。
上面的代码生成以下结果。