JavaFX | CubicCurve with examples - GeeksforGeeks

06 Aug, 2018
CubicCurve is a part of JavaFX.The CubiCurve class defines a cubic Bézier parametric curve segment in (x, y) coordinate space. The Cubic curve passes through the starting point and the ending point and also passes through the two control points. The control points are specified as Bézier control points.Constructor for the class are :
CubicCurve(): creates a new instance of cubic curveCubicCurve(double startX, double startY, double controlX1, double controlY1, double controlX2, double controlY2, double endX, double endY) : creates a instance of cubic curve with specified starting and ending points and two control points.
CubicCurve(): creates a new instance of cubic curve
CubicCurve(double startX, double startY, double controlX1, double controlY1, double controlX2, double controlY2, double endX, double endY) : creates a instance of cubic curve with specified starting and ending points and two control points.
commonly used methods
Java program to create a cubic curveThis program creates a CubicCurve indicated by the name cubic_curve( two control point s, start point and end point is passed as arguments). The CubicCurve will be created inside a scene, which in turn will be hosted inside a stage. The function setTitle() is used to provide title to the stage. Then a Group is created, and the cubic_curve is attached.The group is attached to the scene. Finally, the show() method is called to display the final results.
// Java program to create a cubic curveimport javafx.application.Application;import javafx.scene.Scene;import javafx.scene.shape.DrawMode;import javafx.scene.layout.*;import javafx.event.ActionEvent;import javafx.scene.shape.CubicCurve;import javafx.scene.control.*;import javafx.stage.Stage;import javafx.scene.Group;public class cubic_curve_0 extends Application {      // launch the application    public void start(Stage stage)    {        // set title for the stage        stage.setTitle("creating cubic_curve");          // create a cubic_curve        CubicCurve cubic_curve = new CubicCurve(10.0f, 10.0f, 200.0f, 140.0f, 120.0f, 240.0f, 160.0f, 70.0f);          // create a Group        Group group = new Group(cubic_curve);          // translate the cubic_curve to a position        cubic_curve.setTranslateX(100);        cubic_curve.setTranslateY(100);          // create a scene        Scene scene = new Scene(group, 500, 300);          // set the scene        stage.setScene(scene);          stage.show();    }      public static void main(String args[])    {        // launch the application        launch(args);    }}
Output:
Java program to create a cubic curve and set a fill for cubic curveThis program creates a CubicCurve indicated by the name cubic_curve(two control points, start point and end point are set using setControlX1(), setControlY1(), setControlX2(), setControlY2(), setStartX(), setStartY(), setEndX(), ans setEndY() functions). The CubicCurvewill be created inside a scene, which in turn will be hosted inside a stage. The function setTitle() is used to provide title to the stage. Then a Group is created, and the cubic_curve is attached.The group is attached to the scene. Finally, the show() method is called to display the final results.The function setFill() is used to set fill for the cubic curve.
// Java program to create a cubic curve and set a fill for cubic curveimport javafx.application.Application;import javafx.scene.Scene;import javafx.scene.shape.DrawMode;import javafx.scene.layout.*;import javafx.event.ActionEvent;import javafx.scene.shape.CubicCurve;import javafx.scene.control.*;import javafx.stage.Stage;import javafx.scene.Group;import javafx.scene.paint.Color;public class cubic_curve_1 extends Application {      // launch the application    public void start(Stage stage)    {        // set title for the stage        stage.setTitle("creating cubic_curve");          // create a cubic_curve        CubicCurve cubic_curve = new CubicCurve();          // set start        cubic_curve.setStartX(10.0f);        cubic_curve.setStartY(10.0f);          // set control coordinates        cubic_curve.setControlX1(200.0f);        cubic_curve.setControlY1(140.0f);        cubic_curve.setControlX2(120.0f);        cubic_curve.setControlY2(240.0f);          // set end coordinates        cubic_curve.setEndX(160.0f);        cubic_curve.setEndY(70.0f);          // create a Group        Group group = new Group(cubic_curve);          // translate the cubic_curve to a position        cubic_curve.setTranslateX(100);        cubic_curve.setTranslateY(100);          // set fill for the cubic curve        cubic_curve.setFill(Color.BLUE);          // create a scene        Scene scene = new Scene(group, 500, 300);          // set the scene        stage.setScene(scene);          stage.show();    }      public static void main(String args[])    {        // launch the application        launch(args);    }}
Output:Note : The above programs might not run in online IDE please use an offline compilerReference:https://docs.oracle.com/javase/8/javafx/api/javafx/scene/shape/CubicCurve.html
JavaFX
Java Programs
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
How to Iterate HashMap in Java?
How to Get Elements By Index from HashSet in Java?
Implementing Generic Graph in Java
Parameter Passing Techniques in Java with Examples
Iterate Over the Characters of a String in Java
Java Program to Reverse a List
How to Override compareTo Method in Java?
Java Program to Search for a File in a Directory
Reading and writing in the array using threads
Java Program to Multiply two Matrices of any size