JavaFX 2D Shapes
In some of the applications, we need to show two dimensional shapes to the user. However, JavaFX provides the flexibility to create our own 2D shapes on the screen .
There are various classes which can be used to implement 2D shapes in our application. All these classes resides in javafx.scene.shape package.
This package contains the classes which represents different types of 2D shapes. There are several methods in the classes which deals with the coordinates regarding 2D shape creation.
What are 2D shapes?
In general, a two dimensional shape can be defined as the geometrical figure that can be drawn on the coordinate system consist of X and Y planes. However, this is different from 3D shapes in the sense that each point of the 2D shape always consists of two coordinates (X,Y).
Using JavaFX, we can create 2D shapes such as Line, Rectangle, Circle, Ellipse, Polygon, Cubic Curve, quad curve, Arc, etc. The class javafx.scene.shape.Shape is the base class for all the shape classes.
How to create 2D shapes?
As we have mentioned earlier that every shape is represented by a specific class of the package javafx.scene.shape. For creating a two dimensional shape, the following instructions need to be followed.
1. Instantiate the respective class : for example, Rectangle rect = new Rectangle()
2. Set the required properties for the class using instance setter methods: for example,
3. Add class object to the Group layout: for example,
The following table consists of the JavaFX shape classes along with their descriptions.