javafx rectangle

www.‮gi‬iftidea.com

In JavaFX, a Rectangle is a graphical representation of a rectangle that can be displayed on the screen. Here's an example of how to create and use a Rectangle object:

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

public class MyJavaFXApp extends Application {
    
    @Override
    public void start(Stage primaryStage) {
        // Create a rectangle object
        Rectangle rectangle = new Rectangle(100, 100, Color.BLUE);
        
        // Create a scene and set it on the stage
        Scene scene = new Scene(rectangle, 300, 250);
        primaryStage.setScene(scene);
        
        // Show the stage
        primaryStage.show();
    }
    
    public static void main(String[] args) {
        launch(args);
    }
}

In this example, we create a Rectangle object with a width and height of 100 pixels and a blue fill color. We set the Rectangle object as the content of the Scene object, which is displayed on the screen. You can customize the appearance of the Rectangle object using various properties, such as the fill color, stroke color, stroke width, and corner radius.