解释 JavaFX 中 2D 形状的并集操作
此操作将两个或多个形状作为输入,并返回它们结合所占据的区域,如下所示。
javafx.scene.shape.Shape 类中的union()(静态)方法接受两个形状对象,并返回给定对象的并集操作结果。
示例
import javafx.application.Application; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.paint.Color; import javafx.stage.Stage; import javafx.scene.shape.Circle; import javafx.scene.shape.Shape; public class JavaFXUnionExample extends Application { public void start(Stage stage) { //Drawing circle1 Circle circle1 = new Circle(); circle1.setCenterX(230.0f); circle1.setCenterY(100.0f); circle1.setRadius(75.0f); circle1.setFill(Color.DARKRED); //Drawing Circle2 Circle circle2 = new Circle(); circle2.setCenterX(280.0f); circle2.setCenterY(170.0f); circle2.setRadius(75.0f); circle2.setFill(Color.DARKRED); //Drawing Circle3 Circle circle3 = new Circle(); circle3.setCenterX(330.0f); circle3.setCenterY(100.0f); circle3.setRadius(75.0f); circle3.setFill(Color.DARKRED); //Union operation Shape union = Shape.union(circle1, circle2); union = Shape.union(union, circle3); union.setFill(Color.RED); //Setting the stage Group root = new Group(circle1, circle2, circle3, union); Scene scene = new Scene(root, 595, 300); stage.setTitle("Union Operation"); stage.setScene(scene); stage.show(); } public static void main(String args[]){ launch(args); } }
输出
广告