Tuesday 27 October 2020

JavaFX: QuadCurve Shape

 The Quadcurve class defines a quadratic 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 point (controlX, controlY) as Bézier control point.

 

QuadCurve class define following constructors to define QuadCurve UI component.

 

public QuadCurve()

public QuadCurve(double startX, double startY, double controlX, double controlY, double endX, double endY)

startX: the X coordinate of the start point

startY: the Y coordinate of the start point

controlX: the X coordinate of the control point

controlY: the Y coordinate of the control point

endX: the X coordinate of the end point

endY: the Y coordinate of the end point

 

Example

QuadCurve quadCurve1 = new QuadCurve();

QuadCurve quadCurve2 = new QuadCurve(50, 70, 250, 250, 350, 70);

 

Fxml example

<QuadCurve fx:id="quadCurve1"  fill="lightsalmon" stroke="black" strokeWidth="5"
        startX="50"
        startY="70"
        controlX="250"
        controlY="250"
        endX="350"
        endY="70"
        />

Find the below working application.

 

quadCurveDemo.xml

<?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.QuadCurveController">

    <QuadCurve fx:id="quadCurve1"  fill="lightsalmon" stroke="black" strokeWidth="5"
        startX="50"
        startY="70"
        controlX="250"
        controlY="250"
        endX="350"
        endY="70"
        />
        
    <QuadCurve fx:id="quadCurve1"  fill="lightsalmon" stroke="black" strokeWidth="5"
        startX="350"
        startY="420"
        controlX="200"
        controlY="250"
        endX="350"
        endY="70"
        />

        
</Group>


QuadCurveController.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.QuadCurve;

public class QuadCurveController implements Initializable {

    @FXML
    private QuadCurve quadCurve1;

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

    }

}


QuadCurveDemo.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 QuadCurveDemo extends Application {

    private static final String FXML_FILE = "/quadCurveDemo.fxml";
    private static final String STAGE_TITLE = "QuadCurve 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, 500, 450, Color.WHITE);

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

}


Output






 

  

Previous                                                    Next                                                    Home

No comments:

Post a Comment