JavaFX: Creating A Circle

In creating a JavaFX circle, we would usually use the constructor below.

Circle(double radius, Paint fill)

It is usually sufficed for us to only provide a radius and a color for the circle.

So in the example below, we are using

new Circle(150, Color.DARKKHAKI)

where 150 is the radius of the circle in pixel.

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.StackPane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.stage.Stage;

public class DrawCircle extends Application {

    @Override
    public void start(Stage stage) {
        StackPane root = new StackPane(new Circle(150, Color.DARKKHAKI));
        stage.setScene(new Scene(root, 500, 400));
        stage.show();
    }

    public static void main(String... args) {
        launch(args);
    }
}

circle

 

 

 

Series Navigation<< JavaFX: Inline statement and CSS ID
JavaFX: Setting absolute position for circle >>