Drawing line, circle and rectangle

This is a relatively simple JavaFX program that draws out a line, a circle and a rectangle.

package javafxapplication7;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.scene.shape.Line;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;

public class JavaFXApplication7 extends Application {

    @Override
    public void start(Stage primaryStage) throws Exception {
        initUI(primaryStage);
    }

    public void initUI(Stage stage) {
        Pane root = new Pane();

        Rectangle rect = new Rectangle(50, 100, 100, 100);
        rect.setFill(Color.CADETBLUE);

        Line line = new Line(90, 40, 300, 40);
        line.setStroke(Color.BLACK);

        Circle circle = new Circle(230, 230, 30);
        circle.setFill(Color.CHOCOLATE);

        root.getChildren().addAll(rect, line, circle);

        Scene scene = new Scene(root, 400, 300, Color.WHITESMOKE);

        stage.setTitle("Absolute layout");
        stage.setScene(scene);
        stage.show();
    }

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

drawing

Leave a comment

Leave a Reply