Do you think IIT Guwahati certified course can help you in your career?
No
Introduction
The Ellipse class is used in the JavaFX application to draw ellipses. With the Ellipse, we may connect any two points in the area to create a distinctive form. The javafx.scene.shape.Ellipse class contains all the methods required for this function. Every time an ellipse is drawn, it uses two focus points. The distance to the focus point is the same for any random location on Eclipse.
Each Ellipse includes -
Center: This location marks the intersection of two Ellipse points. At this elliptical intersection, the major and minor axes come together.
Major Axis: The primary axis of an ellipse is represented by its longest diameter.
Minor Axis: The Ellipse's minor axis is the shortest diameter of that Ellipse.
Constructors of Ellipse
Ellipse() : This function Object() , creates a blank function.
Ellipse(double x, double y): Ellipse can be made with a specified x and y radius using this function.
Ellipse(double x, double y, double radiusX, double radiusY): Using the provided x and y coordinates for the center, radius width, and radius height, an Ellipse is created.
How to create an Ellipse?
Three main steps need to be followed to create an ellipse.
Instantiate Ellipse class.
Set the required properties for the class.
Add the class object to the group.
Ellipse creation properties and associated methods
centerX: The setCenterX() method aids in setting the center point of the Ellipse, which is defined by this property of the Ellipse class.
centerY: The setCenterY() method aids in setting the center point of the Ellipse, which may be defined using this attribute of the Ellipse class.
X-radius: The setRadiusX() method and this attribute of the Ellipse class let us specify the width of the Ellipse.
radiusY: The setRadiusY() method and this attribute of the Ellipse class let us choose the height of the Ellipse.
Example
Java program to create an ellipse by passing the center coordinates and radius coordinates as arguments in the constructor.
Code
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.*;
import javafx.event.ActionEvent;
import javafx.scene.shape.Ellipse;
import javafx.scene.control.*;
import javafx.stage.Stage;
import javafx.scene.Group;
public class ellipse_0 extends Application {
// launches the application
public void start(Stage stage)
{
// sets the title for stage
stage.setTitle("creating ellipse");
// creates an ellipse
Ellipse ellipse = new Ellipse(200.0f, 120.0f, 150.0f, 80.f);
// creates a Group
Group group = new Group(ellipse);
// creates a scene
Scene scene = new Scene(group, 500, 300);
// sets the scene
stage.setScene(scene);
stage.show();
}
public static void main(String args[])
{
// launches the application
launch(args);
}
}
Output
Explanation
The name "ellipse" indicates that this application constructs an Ellipse ( the coordinates of the centre and the radius is passed as arguments). The Ellipse will be built inside a scenario that is housed within a stage. The stage's title is provided through the setTitle() method. The ellipse is then attached to a newly established Group. The group is associated with the location. The show() method is then used to display the outcome.
Frequently Asked Questions
Will the above programs work in an online IDE?
No, the programs might work in an online IDE, so it is preferred to use an offline compiler.
What is the getCenterX() property used for?
It returns the X coordinate of the center of the ellipse.
What does an Ellipse class do?
The Ellipse class is used in the JavaFX application to draw ellipses. With the Ellipse, we may connect any two points in the area to create a distinctive form.
Conclusion
This article extensively discussed the implementation and use of the JavaFX Ellipse. We hope that this blog has helped you gain more knowledge regarding the JavaFX Ellipse, check out our articles on Coding Ninjas.