×

JavaFX Arc

In the JavaFX application, in order to draw an arc, the Arc class is used. The Arc allows us to join any points in the space. All methods needed for this purpose are present in the javafx.scene.shape.Arc class.

Properties and corresponding methods to create Arc:

1. centerX

This property of the Arc class allows us to define the center point of Arc which is X co-ordinate and the setCenterX() method helps to set it.

2. centerY

This property of Arc class allows us to define the center point of Arc which is Y co-ordinate and the setCenterY() method helps to set it.

3. radiusX

This property of the Arc class allows us to define the width of the Arc and the setRadiusX() method helps to set it.

4. radiusY

This property of the Arc class allows us to define the height of the Arc and the setRadiusY() method helps to set it.

5. StartAngle

This property of the Arc class allows us to define starting angle of the Arc and the setStartAngle() method helps to set it.

6. Length

This property of the Arc class allows us to define the length of the Arc and the setLength() method helps to set it.

JavaFX 2D Shape – Minor Arc

Example:

import javafx.application.Application;
import javafx.stage.Stage;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.paint.Color;
import javafx.scene.shape.Arc;


  
public class ArcUI extends Application {  


    @Override  
    public void start(Stage primaryStage) throws Exception 
    {  
        Arc newarc = new Arc(220, 220, 120, 180, 0, 80);




   
         Group box = new Group();  
         box.getChildren().addAll(newarc);


         box.getChildren().addAll();      
         Scene scene = new Scene(box,600,400);  
         
           primaryStage.setScene(scene);  
           primaryStage.setTitle("JavaFX 2D shapes - Arc Example");  
           primaryStage.show();  
        }
    public static void main(String[] args) {
        Application.launch(args);
    }
}

Output:

In order to create the Arc in JavaFX, we have to import all the required libraries such as javafx.application.Application, javafx.stage.Stage, javafx.scene.Scene, javafx.scene.Group, javafx.scene.paint.Color, javafx.scene.shape.Arc.

Then we have created one class named ArcUI extending the Application class. Also, we have to override the start method to provide implementation details. This method creates an object of Stage as primaryStage. For the container to hold an Arc, a Group object is created which is then passed to the Scene class object.

Arc is created with all the required values passed in the constructor.

The stage is prepared, the title is set and the show() method is called to display output. In order to run the application, the launch(args) method is invoked. In output Frame like container is displayed with the title, " JavaFX 2D shapes - Arc Example”. Also, it displays minor arc with defined x, y co-ordinates, and width, height with specified starting angle and length.

JavaFX 2D Shape -Arc

JavaFX 2D Shape – Major Arc

Example:

import javafx.application.Application;
import javafx.stage.Stage;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.paint.Color;
import javafx.scene.shape.Arc; 
public class ArcUI extends Application {  


    @Override  
    public void start(Stage primaryStage) throws Exception 
    {  
    Arc newarc = new Arc();
      
    newarc.setCenterX(120);
    newarc.setCenterY(120);
    newarc.setRadiusX(100);
    newarc.setRadiusY(100);
    newarc.setStartAngle(0);
    newarc.setLength(270);


         Group box = new Group();  
         box.getChildren().addAll(newarc);


         box.getChildren().addAll();      
         Scene scene = new Scene(box,600,400);   




           primaryStage.setScene(scene);  
           primaryStage.setTitle("JavaFX 2D shapes - Arc Example");  
           primaryStage.show();  
        }
    public static void main(String[] args) {
        Application.launch(args);
    }
}

Output:

In order to create the major Arc in JavaFX, we have to import all the required libraries such as javafx.application.Application, javafx.stage.Stage, javafx.scene.Scene, javafx.scene.Group, javafx.scene.paint.Color, javafx.scene.shape.Arc.

Then we have created one class named ArcUI extending the Application class. Also, we have to override the start method to provide implementation details. This method creates an object of Stage as primaryStage. For the container to hold major Arc, a Group object is created which is then passed to the Scene class object.

Arc is created with empty constructor and setters for all the required properties.

The stage is prepared, the title is set and the show() method is called to display output. In order to run the application, the launch(args) method is invoked. In output Frame like container is displayed with the title, " JavaFX 2D shapes - Arc Example”. Also, it displays a major arc with defined x, y coordinates and width, height with specified starting angle, and length 270 causing a major arc.

JavaFX 2D Shape -Arc

JavaFX 2D Shape – Round type Arc

Example:

import javafx.application.Application;
import javafx.stage.Stage;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.paint.Color;
import javafx.scene.shape.Arc;
import javafx.scene.shape.ArcType;


  
public class SliderUI extends Application {  


    @Override  
    public void start(Stage primaryStage) throws Exception 
    {  
    Arc newarc = new Arc();
      
    newarc.setCenterX(120);
    newarc.setCenterY(120);
  
    newarc.setRadiusX(100);
    newarc.setRadiusY(100);
  
    newarc.setStartAngle(0);
    newarc.setLength(270);


    newarc.setType(ArcType.ROUND);


         Group box = new Group();  
         box.getChildren().addAll(newarc);


         box.getChildren().addAll();      
         Scene scene = new Scene(box,600,400);  
         
           primaryStage.setScene(scene);  
           primaryStage.setTitle("JavaFX 2D shapes - Arc Example");  
           primaryStage.show();  
        }
    public static void main(String[] args) {
        Application.launch(args);
    }
}

Output:

In order to create the major Arc with specified type in JavaFX, we have to import all the required libraries such as javafx.application.Application, javafx.stage.Stage, javafx.scene.Scene, javafx.scene.Group, javafx.scene.paint.Color, javafx.scene.shape.Arc, javafx.scene.shape.ArcType.

Then we have created one class named ArcUI extending the Application class. Also, we have to override the start method to provide implementation details. This method creates an object of Stage as primaryStage. For the container to hold a major Arc with a specified round type, a Group object is created which is then passed to the Scene class object.

Arc is created with empty constructor and setters for all the required properties. Using setType() method arc type is set to Round.

The stage is prepared, the title is set and the show() method is called to display output. In order to run the application, the launch(args) method is invoked. In output Frame like container is displayed with the title, " JavaFX 2D shapes - Arc Example". Also, it displays a major arc with defined x, y coordinates and width, height with specified starting angle, and length 270 causing a major arc and setType() method with ArcType.ROUND argument shows a rounded arc.

JavaFX 2D Shape -Arc

Related Topics

JavaFX Gaussian Blur

In the JavaFX application, in order to apply various Gaussian blur effect, we use GaussianBlur class. It has the ability to apply blur effect on the given object. All methods...

4 minutes read.

JavaFX Slider

In the JavaFX application, in order to slide over a range of data having values, Slider is used. It provides a pane with a Slider to move over a range...

4 minutes read.

JavaFX Blend

In the JavaFX application, in order to apply various blend effect, we use Blend class. It has the ability to blend the colors of the shape. All methods needed for...

4 minutes read.

JavaFX Polygon

In the JavaFX application, in order to draw a polygon, the Polygon class is used. The Polygon allows us to join any number of points in the space. All methods...

4 minutes read.

JavaFX Bar Chart

In the JavaFX application, in order to create Bar Chart, the BarChart class is used. The Bar Chart allows us to plot data along different bars to show the scales...

4 minutes read.

JavaFX Scatter Chart

In the JavaFX application, in order to create Scatter Chart, the ScatterChart class is used. The Scatter Chart allows us to plot data along the x and y axis of...

4 minutes read.

JavaFX Light Point

In the JavaFX application, in order to apply various LightPoint effect from a single source, we use this class. It has the ability to apply light from a single source...

4 minutes read.

JavaFX Sphere

In the JavaFX application, in order to draw a Sphere, the Sphere class is used. The Sphere allows us to form a 3D shape having circular faces. All methods needed...

4 minutes read.

JavaFX PasswordField

In the JavaFX application, to get the user information and password as input from the user, a form is created using textfields and password fields which allows the user to...

4 minutes read.

JavaFX Box

In the JavaFX application, in order to draw a Box, the Box class is used. The Box allows us to form 3D shape having rectangular faces. All methods needed for...

4 minutes read.

JavaFX Image Input

In the JavaFX application, in order to apply various image input effect, we use the ImageInput class. It has the ability to fill the specified shape with a given image...

4 minutes read.

JavaFX Architecture

JavaFX architecture consists of many built-in components such as JavaFX public API, Scene Graph, Quantum Toolkit, Prism, Glass windowing toolkit, web view, media engines. These components help to develop rich...

3 minutes read.

JavaFX UI Controls

We can make an advanced graphical user interface (GUI) for the JavaFX application using UI Controls and layouts. Various UI elements can be used b the programmer in their application...

3 minutes read.

JavaFX HyperLink

In the JavaFX application, in order to access and use webpages, hyperlinks are used. In HTML anchor tags are used in the same way in JavaFX hyperlinks are used. To...

4 minutes read.

JavaFX Layouts

Layouts in the JavaFX application are treated as a container for different UI elements such as Button, Label, TextArea, etc. Layouts are used as parent container. The layout is used...

3 minutes read.

JavaFX CheckBox

In the JavaFX application, to get the user information in the form of choices from the user, a form is created using checkboxes that allow the user to select two...

4 minutes read.

JavaFX Reflection

In the JavaFX application, in order to apply various reflection effect, we use this class. It has the ability to create the reflection of the given object. This effect adds...

4 minutes read.

JavaFX Color Input

In the JavaFX application, in order to apply various color input effect, we use the ColorInput class. It has the ability to fill the specified shape with a given color...

4 minutes read.

JavaFX Scaling

In the JavaFX application, in order to apply various Scaling effects, we use this class. It has the ability to change the size of the given object. All methods needed...

5 minutes read.

JavaFX Rectangle

In the JavaFX application, in order to draw a rectangle, the Rectangle class is used. The Rectangle allows us to join any four points with x and y coordinates in...

4 minutes read.