JavaFX | Ellipse with examples - GeeksforGeeks

31 Oct, 2019
Ellipse class is a part of the JavaFX library. The ellipse class creates an ellipse on providing the center and X and Y radius. Ellipse class extends Shape class.
Constructors of the class are:
Ellipse(): creates an empty instance of ellipseEllipse(double X, double Y): creates a ellipse with the given x and y radiusEllipse(double x, double y, double X, double Y): creates a ellipse with given center and radius
Ellipse(): creates an empty instance of ellipse
Ellipse(double X, double Y): creates a ellipse with the given x and y radius
Ellipse(double x, double y, double X, double Y): creates a ellipse with given center and radius
Commonly used methods:
Below programs will illustrate the use of ellipse class:
Java program to create ellipse by passing the coordinates of the center and radius as arguments in constructor:This program creates a Ellipse indicated by the name ellipse( the coordinates of the center and the radius is passed as arguments). The Ellipse will be created inside a scene, which in turn will be hosted inside a stage. The function setTitle() is used to provide title to the stage. Then a Group is created, and the ellipse is attached. The group is attached to the scene. Finally, the show() method is called to display the final results.// Java program to create ellipse by passing the// coordinates of the center and radius as arguments in constructorimport 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 {      // launch the application    public void start(Stage stage)    {        // set title for the stage        stage.setTitle("creating ellipse");          // create a ellipse        Ellipse ellipse = new Ellipse(200.0f, 120.0f, 150.0f, 80.f);          // create a Group        Group group = new Group(ellipse);          // create a scene        Scene scene = new Scene(group, 500, 300);          // set the scene        stage.setScene(scene);          stage.show();    }      public static void main(String args[])    {        // launch the application        launch(args);    }}Output:Java program to create ellipse by passing the coordinates of the center and radius using functions setCenterX(), setCenterY() etc.:This program creates a Ellipse indicated by the name ellipse.The coordinates of the center and the radius will be set using functions setCenterX(), setCenterY(), setRadiusX(), and setRadiusY() functions. The Ellipse will be created inside a scene, which in turn will be hosted inside a stage. The function setTitle() is used to provide title to the stage. Then a Group is created, and the ellipse is attached.The group is attached to the scene. Finally, the show() method is called to display the final results.// Java program to create ellipse by passing the// coordinates of the center and radius using// functions setCenterX(), setCenterY() etc.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_1 extends Application {      // launch the application    public void start(Stage stage)    {        // set title for the stage        stage.setTitle("creating ellipse");          // create a ellipse        Ellipse ellipse = new Ellipse();          // set center        ellipse.setCenterX(150.0f);        ellipse.setCenterY(120.0f);          // set radius        ellipse.setRadiusX(130.0f);        ellipse.setRadiusY(100.0f);          // create a Group        Group group = new Group(ellipse);          // create a scene        Scene scene = new Scene(group, 500, 300);          // set the scene        stage.setScene(scene);          stage.show();    }      public static void main(String args[])    {        // launch the application        launch(args);    }}Output:Java program to create ellipse by passing the coordinates of the center and radius using functions setCenterX(), setCenterY(), and set a fill using setFill() function:This program creates a Ellipse indicated by the name ellipse.The coordinates of the center and the radius will be set using functions setCenterX(), setCenterY(), setRadiusX(), and setRadiusY() functions.The function setFill() will be used to set the fill of the ellipse. The Ellipse will be created inside a scene, which in turn will be hosted inside a stage. The function setTitle() is used to provide title to the stage. Then a Group is created, and the ellipse is attached.The group is attached to the scene. Finally, the show() method is called to display the final results.// Java program to create ellipse by passing the// coordinates of the center and radius using// functions setCenterX(), setCenterY(), and// set a fill using setFill() functionimport 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.scene.paint.Color;import javafx.stage.Stage;import javafx.scene.Group;public class ellipse_2 extends Application {      // launch the application    public void start(Stage stage)    {        // set title for the stage        stage.setTitle("creating ellipse");          // create a ellipse        Ellipse ellipse = new Ellipse();          // set center        ellipse.setCenterX(150.0f);        ellipse.setCenterY(120.0f);          // set radius        ellipse.setRadiusX(130.0f);        ellipse.setRadiusY(100.0f);          // set fill        ellipse.setFill(Color.BLUE);          // create a Group        Group group = new Group(ellipse);          // create a scene        Scene scene = new Scene(group, 500, 300);          // set the scene        stage.setScene(scene);          stage.show();    }      public static void main(String args[])    {        // launch the application        launch(args);    }}Output:Note : The above programs might not run in an online IDE please use an offline compiler.Reference: https://docs.oracle.com/javase/8/javafx/api/javafx/scene/shape/Ellipse.htmlMy Personal Notes
arrow_drop_upSave
Java program to create ellipse by passing the coordinates of the center and radius as arguments in constructor:This program creates a Ellipse indicated by the name ellipse( the coordinates of the center and the radius is passed as arguments). The Ellipse will be created inside a scene, which in turn will be hosted inside a stage. The function setTitle() is used to provide title to the stage. Then a Group is created, and the ellipse is attached. The group is attached to the scene. Finally, the show() method is called to display the final results.// Java program to create ellipse by passing the// coordinates of the center and radius as arguments in constructorimport 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 {      // launch the application    public void start(Stage stage)    {        // set title for the stage        stage.setTitle("creating ellipse");          // create a ellipse        Ellipse ellipse = new Ellipse(200.0f, 120.0f, 150.0f, 80.f);          // create a Group        Group group = new Group(ellipse);          // create a scene        Scene scene = new Scene(group, 500, 300);          // set the scene        stage.setScene(scene);          stage.show();    }      public static void main(String args[])    {        // launch the application        launch(args);    }}Output:
This program creates a Ellipse indicated by the name ellipse( the coordinates of the center and the radius is passed as arguments). The Ellipse will be created inside a scene, which in turn will be hosted inside a stage. The function setTitle() is used to provide title to the stage. Then a Group is created, and the ellipse is attached. The group is attached to the scene. Finally, the show() method is called to display the final results.
// Java program to create ellipse by passing the// coordinates of the center and radius as arguments in constructorimport 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 {      // launch the application    public void start(Stage stage)    {        // set title for the stage        stage.setTitle("creating ellipse");          // create a ellipse        Ellipse ellipse = new Ellipse(200.0f, 120.0f, 150.0f, 80.f);          // create a Group        Group group = new Group(ellipse);          // create a scene        Scene scene = new Scene(group, 500, 300);          // set the scene        stage.setScene(scene);          stage.show();    }      public static void main(String args[])    {        // launch the application        launch(args);    }}
Output:
Java program to create ellipse by passing the coordinates of the center and radius using functions setCenterX(), setCenterY() etc.:This program creates a Ellipse indicated by the name ellipse.The coordinates of the center and the radius will be set using functions setCenterX(), setCenterY(), setRadiusX(), and setRadiusY() functions. The Ellipse will be created inside a scene, which in turn will be hosted inside a stage. The function setTitle() is used to provide title to the stage. Then a Group is created, and the ellipse is attached.The group is attached to the scene. Finally, the show() method is called to display the final results.// Java program to create ellipse by passing the// coordinates of the center and radius using// functions setCenterX(), setCenterY() etc.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_1 extends Application {      // launch the application    public void start(Stage stage)    {        // set title for the stage        stage.setTitle("creating ellipse");          // create a ellipse        Ellipse ellipse = new Ellipse();          // set center        ellipse.setCenterX(150.0f);        ellipse.setCenterY(120.0f);          // set radius        ellipse.setRadiusX(130.0f);        ellipse.setRadiusY(100.0f);          // create a Group        Group group = new Group(ellipse);          // create a scene        Scene scene = new Scene(group, 500, 300);          // set the scene        stage.setScene(scene);          stage.show();    }      public static void main(String args[])    {        // launch the application        launch(args);    }}Output:
This program creates a Ellipse indicated by the name ellipse.The coordinates of the center and the radius will be set using functions setCenterX(), setCenterY(), setRadiusX(), and setRadiusY() functions. The Ellipse will be created inside a scene, which in turn will be hosted inside a stage. The function setTitle() is used to provide title to the stage. Then a Group is created, and the ellipse is attached.The group is attached to the scene. Finally, the show() method is called to display the final results.
// Java program to create ellipse by passing the// coordinates of the center and radius using// functions setCenterX(), setCenterY() etc.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_1 extends Application {      // launch the application    public void start(Stage stage)    {        // set title for the stage        stage.setTitle("creating ellipse");          // create a ellipse        Ellipse ellipse = new Ellipse();          // set center        ellipse.setCenterX(150.0f);        ellipse.setCenterY(120.0f);          // set radius        ellipse.setRadiusX(130.0f);        ellipse.setRadiusY(100.0f);          // create a Group        Group group = new Group(ellipse);          // create a scene        Scene scene = new Scene(group, 500, 300);          // set the scene        stage.setScene(scene);          stage.show();    }      public static void main(String args[])    {        // launch the application        launch(args);    }}
Output:
Java program to create ellipse by passing the coordinates of the center and radius using functions setCenterX(), setCenterY(), and set a fill using setFill() function:This program creates a Ellipse indicated by the name ellipse.The coordinates of the center and the radius will be set using functions setCenterX(), setCenterY(), setRadiusX(), and setRadiusY() functions.The function setFill() will be used to set the fill of the ellipse. The Ellipse will be created inside a scene, which in turn will be hosted inside a stage. The function setTitle() is used to provide title to the stage. Then a Group is created, and the ellipse is attached.The group is attached to the scene. Finally, the show() method is called to display the final results.// Java program to create ellipse by passing the// coordinates of the center and radius using// functions setCenterX(), setCenterY(), and// set a fill using setFill() functionimport 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.scene.paint.Color;import javafx.stage.Stage;import javafx.scene.Group;public class ellipse_2 extends Application {      // launch the application    public void start(Stage stage)    {        // set title for the stage        stage.setTitle("creating ellipse");          // create a ellipse        Ellipse ellipse = new Ellipse();          // set center        ellipse.setCenterX(150.0f);        ellipse.setCenterY(120.0f);          // set radius        ellipse.setRadiusX(130.0f);        ellipse.setRadiusY(100.0f);          // set fill        ellipse.setFill(Color.BLUE);          // create a Group        Group group = new Group(ellipse);          // create a scene        Scene scene = new Scene(group, 500, 300);          // set the scene        stage.setScene(scene);          stage.show();    }      public static void main(String args[])    {        // launch the application        launch(args);    }}Output:Note : The above programs might not run in an online IDE please use an offline compiler.Reference: https://docs.oracle.com/javase/8/javafx/api/javafx/scene/shape/Ellipse.htmlMy Personal Notes
arrow_drop_upSave
This program creates a Ellipse indicated by the name ellipse.The coordinates of the center and the radius will be set using functions setCenterX(), setCenterY(), setRadiusX(), and setRadiusY() functions.The function setFill() will be used to set the fill of the ellipse. The Ellipse will be created inside a scene, which in turn will be hosted inside a stage. The function setTitle() is used to provide title to the stage. Then a Group is created, and the ellipse is attached.The group is attached to the scene. Finally, the show() method is called to display the final results.
// Java program to create ellipse by passing the// coordinates of the center and radius using// functions setCenterX(), setCenterY(), and// set a fill using setFill() functionimport 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.scene.paint.Color;import javafx.stage.Stage;import javafx.scene.Group;public class ellipse_2 extends Application {      // launch the application    public void start(Stage stage)    {        // set title for the stage        stage.setTitle("creating ellipse");          // create a ellipse        Ellipse ellipse = new Ellipse();          // set center        ellipse.setCenterX(150.0f);        ellipse.setCenterY(120.0f);          // set radius        ellipse.setRadiusX(130.0f);        ellipse.setRadiusY(100.0f);          // set fill        ellipse.setFill(Color.BLUE);          // create a Group        Group group = new Group(ellipse);          // create a scene        Scene scene = new Scene(group, 500, 300);          // set the scene        stage.setScene(scene);          stage.show();    }      public static void main(String args[])    {        // launch the application        launch(args);    }}
Output:
Note : The above programs might not run in an online IDE please use an offline compiler.Reference: https://docs.oracle.com/javase/8/javafx/api/javafx/scene/shape/Ellipse.html
ManasChhabra2
JavaFX
Java
Java Programs
Java
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
Functional Interfaces in Java
Stream In Java
Constructors in Java
Different ways of Reading a text file in Java
Exceptions in Java
Convert a String to Character array in Java
Java Programming Examples
Convert Double to Integer in Java
Implementing a Linked List in Java using Class
Factory method design pattern in Java