Tuesday 27 October 2020

JavaFX: CubicCurve shape

 'CubicCurve' class is used to define a cubic B'zier parametric curve segment in (x, y) coordinate space.

 

Drawing a curve that intersects both the specified coordinates (startX, startY) and (endX, enfY), using the specified points (controlX1, controlY1) and (controlX2, controlY2) as B'zier control points.

 

CubicCurve class provide below constructors to define CubicCurve widget.

 

public CubicCurve()

public CubicCurve(double startX, double startY, double controlX1, double controlY1, double controlX2, double controlY2, double endX, double endY)

startX: the X coordinate of the start point

startY: the Y coordinate of the start point

controlX1: the X coordinate of the first control point

controlY1: the Y coordinate of the first control point

controlX2: the X coordinate of the second control point

controlY2: the Y coordinate of the second control point

endX: the X coordinate of the end point

endY: the Y coordinate of the end point

 

Example

CubicCurve cubicCurve1 = new CubicCurve();

CubicCurve cubicCurve2 = new CubicCurve(50, 400, 150, 100, 250, 500, 400, 70);

 

FXML example

    <CubicCurve fx:id="cubicCurve"  fill="lightsalmon" stroke="black" strokeWidth="5"

        startX="50"

        startY="400"

        controlX1="150"

        controlY1="100"

        controlX2="250"

        controlY2="500"

        endX="400"

        endY="70"

        />

 

Find the below working example.

 

cubicCurveDemo.fxml

<?import javafx.scene.*?>
<?import javafx.scene.shape.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.*?>

<Group xmlns:fx="http://javafx.com/fxml" fx:controller="com.sample.app.controller.CubicCurveController">

        
    <CubicCurve fx:id="cubicCurve"  fill="lightsalmon" stroke="black" strokeWidth="5"
        startX="50"
        startY="400"
        controlX1="150"
        controlY1="100"
        controlX2="250"
        controlY2="500"
        endX="400"
        endY="70"
        />

        
</Group>

 

CubicCurveController.java

package com.sample.app.controller;

import java.net.URL;
import java.util.ResourceBundle;

import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.shape.CubicCurve;

public class CubicCurveController implements Initializable {

    @FXML
    private CubicCurve cubicCurve;

    @Override
    public void initialize(URL location, ResourceBundle resources) {

    }

}

CubicCurveDemo.java


package com.sample.app;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.paint.Color;
import javafx.stage.Stage;

public class CubicCurveDemo extends Application {

    private static final String FXML_FILE = "/cubicCurveDemo.fxml";
    private static final String STAGE_TITLE = "CubicCurve Demo";

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

    }

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

        Parent root = (Parent) FXMLLoader.load(this.getClass().getResource(FXML_FILE));

        Scene scene = new Scene(root, 600, 500, Color.WHITE);

        primaryStage.setTitle(STAGE_TITLE);
        primaryStage.setScene(scene);
        primaryStage.show();
    }

}


Output





Previous                                                    Next                                                    Home

No comments:

Post a Comment