
- Java Tutorial
- Java - Home
- Java - Overview
- Java - Environment Setup
- Java - Basic Syntax
- Java - Object & Classes
- Java - Constructors
- Java - Basic Datatypes
- Java - Variable Types
- Java - Modifier Types
- Java - Basic Operators
- Java - Loop Control
- Java - Decision Making
- Java - Numbers
- Java - Characters
- Java - Strings
- Java - Arrays
- Java - Date & Time
- Java - Regular Expressions
- Java - Methods
- Java - Files and I/O
- Java - Exceptions
- Java - Inner classes
- Java Object Oriented
- Java - Inheritance
- Java - Overriding
- Java - Polymorphism
- Java - Abstraction
- Java - Encapsulation
- Java - Interfaces
- Java - Packages
- Java Advanced
- Java - Data Structures
- Java - Collections
- Java - Generics
- Java - Serialization
- Java - Networking
- Java - Sending Email
- Java - Multithreading
- Java - Applet Basics
- Java - Documentation
- Java Useful Resources
- Java - Questions and Answers
- Java - Quick Guide
- Java - Useful Resources
- Java - Discussion
- Java - Examples
Explain the Union operation on 2D shapes in JavaFX
This operation takes two or more shapes as inputs and returns the area occupied by them combined as shown below.
The union() (static) method of the javafx.scene.shape.Shape class accepts two Shape objects and returns the result of the union operation of the given objects.
Example
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); } }
Output
- Related Articles
- Explain the Intersect operation on 2D shapes in JavaFX
- Explain the Subtract operation on 2D shapes in JavaFX
- Explain the Fill property of 2D shapes in JavaFX
- Explain the Stroke property of 2D shapes in JavaFX
- Explain the smooth property of 2D shapes in JavaFX
- Explain the Stroke Type property of 2D shapes in JavaFX
- Explain the Stroke Width property of 2D shapes in JavaFX
- Explain the Stroke Line Join property of 2D shapes in JavaFX
- Explain the Stroke Miter Limit property of 2D shapes in JavaFX
- Explain the Stroke Line Cap property of 2D shapes in JavaFX
- Explain the stroke Dash Offset property of 2D shapes in JavaFX
- What are various 2D shapes provided by JavaFX?
- Explain union operation in relational algebra (DBMS)?
- Explain the Properties of 2D objects in JavaFX
- Explain the cull face property of 3D shapes in JavaFX

Advertisements