JavaFX – Shearing Transformation

JavaFX – Shearing Transformation ”; Previous Next A transformation that slants the shape of an object is called the Shear Transformation. There are two shear transformations X-Shear and Y-Shear. One shifts the X coordinate values and the other shifts the Y coordinate values. However, in both the cases only one coordinate changes its coordinates and the other preserves its values. Shearing is also termed as Skewing. Example 1 Following is the program which demonstrates shearing in JavaFX. Here, we are creating 2 polygons (nodes) at the same location, with the same dimensions, but with different colors (Blue and Transparent). We are also applying shearing on the transparent polygon. Save this code in a file with the name XShearingExample.java. import javafx.application.Application; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.paint.Color; import javafx.scene.shape.Polygon; import javafx.scene.transform.Shear; import javafx.stage.Stage; public class XShearingExample extends Application { @Override public void start(Stage stage) { Polygon hexagon1 = new Polygon(); //Adding coordinates to the hexagon hexagon1.getPoints().addAll(new Double[]{ 200.0, 50.0, 400.0, 50.0, 450.0, 150.0, 400.0, 250.0, 200.0, 250.0, 150.0, 150.0, }); //Setting the fill color for the hexagon hexagon1.setFill(Color.BLUE); hexagon1.setStroke(Color.BLACK); Polygon hexagon2 = new Polygon(); //Adding coordinates to the hexagon hexagon2.getPoints().addAll(new Double[]{ 200.0, 50.0, 400.0, 50.0, 450.0, 150.0, 400.0, 250.0, 200.0, 250.0, 150.0, 150.0, }); //Setting the fill color for the hexagon hexagon2.setFill(Color.TRANSPARENT); hexagon2.setStroke(Color.BLACK); //Creating shear transformation Shear shear = new Shear(); //Setting the pivot points shear.setPivotX(200); shear.setPivotY(250); //Setting the dimensions for the shear shear.setX(0.5); shear.setY(0.0); //Adding the transformation to the polygon hexagon2.getTransforms().addAll(shear); //Creating a Group object Group root = new Group(hexagon1, hexagon2); //Creating a scene object Scene scene = new Scene(root, 600, 300); //Setting title to the Stage stage.setTitle(“Shearing Example “); //Adding scene to the stage stage.setScene(scene); //Displaying the contents of the stage stage.show(); } public static void main(String args[]){ launch(args); } } Compile and execute the saved java file from the command prompt using the following commands. javac –module-path %PATH_TO_FX% –add-modules javafx.controls XShearingExample.java java –module-path %PATH_TO_FX% –add-modules javafx.controls XShearingExample Output On executing, the above program generates a JavaFX window as shown below. Example 2 In the previous example, we have seen how to perform X-Shear by skewing the hexagon with respect to the X-axis. In this example, let us see Y-Shear performed on another JavaFX 2D shape, say pentagon. Save this code in a file with the name YShearingExample.java. import javafx.application.Application; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.paint.Color; import javafx.scene.shape.Polygon; import javafx.scene.transform.Shear; import javafx.stage.Stage; public class YShearingExample extends Application { @Override public void start(Stage stage) { Polygon pentagon1 = new Polygon(); //Adding coordinates to the pentagon pentagon1.getPoints().addAll(new Double[]{ 200.0, 50.0, 400.0, 50.0, 450.0, 150.0, 400.0, 250.0, 200.0, 250.0, }); //Setting the fill color for the pentagon pentagon1.setFill(Color.ORANGE); pentagon1.setStroke(Color.BLACK); Polygon pentagon2 = new Polygon(); //Adding coordinates to the pentagon pentagon2.getPoints().addAll(new Double[]{ 200.0, 50.0, 400.0, 50.0, 450.0, 150.0, 400.0, 250.0, 200.0, 250.0, }); //Setting the fill color for the pentagon pentagon2.setFill(Color.TRANSPARENT); pentagon2.setStroke(Color.BLACK); //Creating shear transformation Shear shear = new Shear(); //Setting the pivot points shear.setPivotX(200); shear.setPivotY(250); //Setting the dimensions for the shear shear.setX(0.0); shear.setY(0.5); //Adding the transformation to the polygon pentagon2.getTransforms().addAll(shear); //Creating a Group object Group root = new Group(pentagon1, pentagon2); //Creating a scene object Scene scene = new Scene(root, 600, 400); //Setting title to the Stage stage.setTitle(“Shearing Example “); //Adding scene to the stage stage.setScene(scene); //Displaying the contents of the stage stage.show(); } public static void main(String args[]){ launch(args); } } Compile and execute the saved java file from the command prompt using the following commands. javac –module-path %PATH_TO_FX% –add-modules javafx.controls YShearingExample.java java –module-path %PATH_TO_FX% –add-modules javafx.controls YShearingExample Output On executing, the above program generates a JavaFX window as shown below. Print Page Previous Next Advertisements ”;

JavaFX – Event Filters

JavaFX – Event Filters ”; Previous Next Event filters enable you to handle an event during the event capturing phase of event processing. Event Capturing phase in event handling is a phase where an event travels through all the nodes in a dispatch chain. A node in this dispatch chain can either have one or more filters, or no filters at all, to handle an event. Event Filters process the events, like mouse events, scroll events, keyboard events, etc. during this Event Capturing phase. However, these Event Filters need to be registered with the node in order to provide the event handling logic to the event generated on the node. If a node does not contain an event filter, the event is directly passed to the target node. Otherwise, a single filter can be used for more than one node and event types. To simply summarize, Event filters are used to enable the parent node to provide common processing for its child nodes; and also to intercept an event and prevent child nodes from acting on the event. Adding and Removing Event Filter To add an event filter to a node, you need to register this filter using the method addEventFilter() of the Node class. //Creating the mouse event handler EventHandler<MouseEvent> eventHandler = new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent e) { System.out.println(“Hello World”); circle.setFill(Color.DARKSLATEBLUE); } }; //Adding event Filter Circle.addEventFilter(MouseEvent.MOUSE_CLICKED, eventHandler); In the same way, you can remove a filter using the method removeEventFilter() as shown below − circle.removeEventFilter(MouseEvent.MOUSE_CLICKED, eventHandler); Example Following is an example demonstrating the event handling in JavaFX using the event filters. Save this code in a file with name EventFiltersExample.java. import javafx.application.Application; import static javafx.application.Application.launch; import javafx.event.EventHandler; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.input.MouseEvent; import javafx.scene.paint.Color; import javafx.scene.shape.Circle; import javafx.scene.text.Font; import javafx.scene.text.FontWeight; import javafx.scene.text.Text; import javafx.stage.Stage; public class EventFiltersExample extends Application { @Override public void start(Stage stage) { //Drawing a Circle Circle circle = new Circle(); //Setting the position of the circle circle.setCenterX(300.0f); circle.setCenterY(135.0f); //Setting the radius of the circle circle.setRadius(25.0f); //Setting the color of the circle circle.setFill(Color.BROWN); //Setting the stroke width of the circle circle.setStrokeWidth(20); //Setting the text Text text = new Text(“Click on the circle to change its color”); //Setting the font of the text text.setFont(Font.font(null, FontWeight.BOLD, 15)); //Setting the color of the text text.setFill(Color.CRIMSON); //setting the position of the text text.setX(150); text.setY(50); //Creating the mouse event handler EventHandler<MouseEvent> eventHandler = new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent e) { System.out.println(“Hello World”); circle.setFill(Color.DARKSLATEBLUE); } }; //Registering the event filter circle.addEventFilter(MouseEvent.MOUSE_CLICKED, eventHandler); //Creating a Group object Group root = new Group(circle, text); //Creating a scene object Scene scene = new Scene(root, 600, 300); //Setting the fill color to the scene scene.setFill(Color.LAVENDER); //Setting title to the Stage stage.setTitle(“Event Filters Example”); //Adding scene to the stage stage.setScene(scene); //Displaying the contents of the stage stage.show(); } public static void main(String args[]){ launch(args); } } Compile and execute the saved java file from the command prompt using the following commands. javac –module-path %PATH_TO_FX% –add-modules javafx.controls EventFiltersExample.java java –module-path %PATH_TO_FX% –add-modules javafx.controls EventFiltersExample Output On executing, the above program generates a JavaFX window as shown below. Example We have seen how event filters processing a mouse event. Now, let us try to register event filters on other events like Keyboard events. Save this code in a file with name EventFilterKeyboard.java. import javafx.application.Application; import javafx.event.EventHandler; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.control.Label; import javafx.scene.control.TextField; import javafx.scene.input.KeyEvent; import javafx.scene.paint.Color; import javafx.stage.Stage; public class EventFilterKeyboard extends Application{ @Override public void start(Stage primaryStage) throws Exception { //Adding Labels and TextFileds to the scene Label label1 = new Label(“Insert Key”); Label label2 = new Label(“Event”); label1.setTranslateX(100); label1.setTranslateY(100); label2.setTranslateX(100); label2.setTranslateY(150); TextField text1 = new TextField(); TextField text2 = new TextField(); text1.setTranslateX(250); text1.setTranslateY(100); text2.setTranslateX(250); text2.setTranslateY(150); //Creating EventHandler Object EventHandler<KeyEvent> filter = new EventHandler<KeyEvent>() { @Override public void handle(KeyEvent event) { text2.setText(“Event : “+event.getEventType()); text1.setText(event.getText()); event.consume(); } }; //Registering Event Filter for the event generated on text field text1.addEventFilter(KeyEvent.ANY, filter); //Setting Group and Scene Group root = new Group(); root.getChildren().addAll(label1,label2,text1,text2); Scene scene = new Scene(root, 500, 300); primaryStage.setScene(scene); primaryStage.setTitle(“Adding Event Filter”); primaryStage.show(); } public static void main(String[] args) { launch(args); } } Compile and execute the saved java file from the command prompt using the following commands. javac –module-path %PATH_TO_FX% –add-modules javafx.controls EventFilterKeyboard.java java –module-path %PATH_TO_FX% –add-modules javafx.controls EventFilterKeyboard Output On executing, the above program generates a JavaFX window as shown below. Print Page Previous Next Advertisements ”;

JavaFX – Material Property

JavaFX – Material Property ”; Previous Next Until now, when we addressed the properties of a JavaFX shape object, it always only included the color of shape fill and type of shape strokes. However, JavaFX also allows you to assign the type of material for a 3D shape. Material of a 3D object is nothing but the type of texture used to create a 3D object. For example, a box in real world can be made of different materials; like a cardboard, a metal, wood, or just any other solid. All of these form the same shape but with a different material. Similarly, JavaFX allows you to choose the type of material used to create a 3D object. Material Property The Material property is of the type Material and it is used to choose the surface of the material of a 3D shape. You can set the material of a 3D shape using the method setMaterial() as follows − cylinder.setMaterial(material); As mentioned above for this method, you need to pass an object of the type Material. The PhongMaterial class of the package javafx.scene.paint is a sub class of this class and provides 7 properties that represent a Phong shaded material. You can apply all these type of materials to the surface of a 3D shape using the setter methods of these properties. Following are the type of materials that are available in JavaFX − bumpMap − This represents a normal map stored as a RGB Image. diffuseMap − This represents a diffuse map. selfIlluminationMap − This represents a self-illumination map of this PhongMaterial. specularMap − This represents a specular map of this PhongMaterial. diffuseColor − This represents a diffuse color of this PhongMaterial. specularColor − This represents a specular color of this PhongMaterial. specularPower − This represents a specular power of this PhongMaterial. By default, the material of a 3-Dimensional shape is a PhongMaterial with a diffuse color of light gray. Example Following is an example which displays various materials on the cylinder. Save this code in a file with the name CylinderMaterials.java. import javafx.application.Application; import javafx.scene.Group; import javafx.scene.PerspectiveCamera; import javafx.scene.Scene; import javafx.scene.image.Image; import javafx.scene.paint.Color; import javafx.scene.paint.PhongMaterial; import javafx.scene.shape.Cylinder; import javafx.stage.Stage; public class CylinderMaterials extends Application { @Override public void start(Stage stage) { //Drawing Cylinder1 Cylinder cylinder1 = new Cylinder(); //Setting the properties of the Cylinder cylinder1.setHeight(130.0f); cylinder1.setRadius(30.0f); //Setting the position of the Cylinder cylinder1.setTranslateX(100); cylinder1.setTranslateY(75); //Preparing the phong material of type bump map PhongMaterial material1 = new PhongMaterial(); material1.setBumpMap(new Image (“http://www.tutorialspoint.com/images/tplogo.gif”)); //Setting the bump map material to Cylinder1 cylinder1.setMaterial(material1); //Drawing Cylinder2 Cylinder cylinder2 = new Cylinder(); //Setting the properties of the Cylinder cylinder2.setHeight(130.0f); cylinder2.setRadius(30.0f); //Setting the position of the Cylinder cylinder2.setTranslateX(200); cylinder2.setTranslateY(75); //Preparing the phong material of type diffuse map PhongMaterial material2 = new PhongMaterial(); material2.setDiffuseMap(new Image (“http://www.tutorialspoint.com/images/tp-logo.gif”)); //Setting the diffuse map material to Cylinder2 cylinder2.setMaterial(material2); //Drawing Cylinder3 Cylinder cylinder3 = new Cylinder(); //Setting the properties of the Cylinder cylinder3.setHeight(130.0f); cylinder3.setRadius(30.0f); //Setting the position of the Cylinder cylinder3.setTranslateX(300); cylinder3.setTranslateY(75); //Preparing the phong material of type Self Illumination Map PhongMaterial material3 = new PhongMaterial(); material3.setSelfIlluminationMap(new Image (“http://www.tutorialspoint.com/images/tp-logo.gif”)); //Setting the Self Illumination Map material to Cylinder3 cylinder3.setMaterial(material3); //Drawing Cylinder4 Cylinder cylinder4 = new Cylinder(); //Setting the properties of the Cylinder cylinder4.setHeight(130.0f); cylinder4.setRadius(30.0f); //Setting the position of the Cylinder cylinder4.setTranslateX(400); cylinder4.setTranslateY(75); //Preparing the phong material of type Specular Map PhongMaterial material4 = new PhongMaterial(); material4.setSpecularMap(new Image (“http://www.tutorialspoint.com/images/tp-logo.gif”)); //Setting the Specular Map material to Cylinder4 cylinder4.setMaterial(material4); //Drawing Cylinder5 Cylinder cylinder5 = new Cylinder(); //Setting the properties of the Cylinder cylinder5.setHeight(130.0f); cylinder5.setRadius(30.0f); //Setting the position of the Cylinder cylinder5.setTranslateX(100); cylinder5.setTranslateY(300); //Preparing the phong material of type diffuse color PhongMaterial material5 = new PhongMaterial(); material5.setDiffuseColor(Color.BLANCHEDALMOND); //Setting the diffuse color material to Cylinder5 cylinder5.setMaterial(material5); //Drawing Cylinder6 Cylinder cylinder6 = new Cylinder(); //Setting the properties of the Cylinder cylinder6.setHeight(130.0f); cylinder6.setRadius(30.0f); //Setting the position of the Cylinder cylinder6.setTranslateX(200); cylinder6.setTranslateY(300); //Preparing the phong material of type specular color PhongMaterial material6 = new PhongMaterial(); //setting the specular color map to the material material6.setSpecularColor(Color.BLANCHEDALMOND); //Setting the specular color material to Cylinder6 cylinder6.setMaterial(material6); //Drawing Cylinder7 Cylinder cylinder7 = new Cylinder(); //Setting the properties of the Cylinder cylinder7.setHeight(130.0f); cylinder7.setRadius(30.0f); //Setting the position of the Cylinder cylinder7.setTranslateX(300); cylinder7.setTranslateY(300); //Preparing the phong material of type Specular Power PhongMaterial material7 = new PhongMaterial(); material7.setSpecularPower(0.1); //Setting the Specular Power material to the Cylinder cylinder7.setMaterial(material7); //Creating a Group object Group root = new Group(cylinder1 ,cylinder2, cylinder3, cylinder4, cylinder5, cylinder6, cylinder7); //Creating a scene object Scene scene = new Scene(root, 600, 400); //Setting camera PerspectiveCamera camera = new PerspectiveCamera(false); camera.setTranslateX(0); camera.setTranslateY(0); camera.setTranslateZ(-10); scene.setCamera(camera); //Setting title to the Stage stage.setTitle(“Drawing a cylinder”); //Adding scene to the stage stage.setScene(scene); //Displaying the contents of the stage stage.show(); } public static void main(String args[]){ launch(args); } } Compile and execute the saved java file from the command prompt using the following commands. javac –module-path %PATH_TO_FX% –add-modules javafx.controls CylinderMaterials.java java –module-path %PATH_TO_FX% –add-modules javafx.controls CylinderMaterials Output

JavaFX – Stroke Property

JavaFX – Stroke Property ”; Previous Next The Stroke Fill property is used to change the colours of 2D object itself. However, we can also change the colour of a 2D object”s boundary. In JavaFX, while creating a 2D object, there are only two parts you can work with, if you want to improve the quality of the shape; i.e., the enclosed area of the shape and the boundary of the shape. Hence, the properties provided by JavaFX include designing both these parts. In this chapter, we will learn about the Stroke property in detail. Stroke Property The Stroke property in JavaFX is used to change colours of the shape boundary. This property is of the type Paint and it represents the color of the boundary line of the shape. You can set a value to this property using the method setStroke(). This method is a part of javafx.scene.paint package and takes the Color object as a parameter value as shown below − path.setStroke(Color.RED) By default, the color of the stroke is black. Following is a diagram of a triangle with different stroke colors. Example We will see an example demonstrating how to colour the boundary of a 2D shape in JavaFX. In here, we are drawing a 2D shape, say a rectangle. By default, the rectangle will be coloured black; we will try to change its boundary colour to Violet. Save the file with the name StrokeExample.java. import javafx.application.Application; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.shape.Rectangle; import javafx.scene.shape.Shape; import javafx.scene.paint.Color; import javafx.stage.Stage; public class StrokeExample extends Application { @Override public void start(Stage stage) { //Creating a Rectangle Rectangle rectangle = new Rectangle(50.0f, 50.0f, 200.0f, 100.0f); rectangle.setStroke(Color.VIOLET); rectangle.setStrokeWidth(7.0); //Creating a Group object Group root = new Group(rectangle); //Creating a scene object Scene scene = new Scene(root, 300, 300); //Setting title to the Stage stage.setTitle(“Drawing a Rectangle”); //Adding scene to the stage stage.setScene(scene); //Displaying the contents of the stage stage.show(); } public static void main(String args[]){ launch(args); } } Compile and execute the saved java file from the command prompt using the following commands. javac –module-path %PATH_TO_FX% –add-modules javafx.controls StrokeExample.java java –module-path %PATH_TO_FX% –add-modules javafx.controls StrokeExample Output On executing, the above program generates a JavaFX window displaying a rectangle with a stroke coloured violet as shown below. Example In this example, we are drawing a polygon and change its boundary colour to RED. Save the file with the name StrokePolygonExample.java. import javafx.application.Application; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.shape.Polygon; import javafx.scene.shape.Shape; import javafx.scene.paint.Color; import javafx.stage.Stage; public class StrokePolygonExample extends Application { @Override public void start(Stage stage) { //Creating a Polygon Polygon polygon = new Polygon(); //Adding coordinates to the polygon polygon.getPoints().addAll(new Double[]{ 100.0, 50.0, 200.0, 50.0, 250.0, 150.0, 200.0, 250.0, 100.0, 250.0, }); polygon.setStroke(Color.RED); polygon.setStrokeWidth(5.0); //Creating a Group object Group root = new Group(polygon); //Creating a scene object Scene scene = new Scene(root, 300, 300); //Setting title to the Stage stage.setTitle(“Drawing a Polygon”); //Adding scene to the stage stage.setScene(scene); //Displaying the contents of the stage stage.show(); } public static void main(String args[]){ launch(args); } } Compile and execute the saved java file from the command prompt using the following commands. javac –module-path %PATH_TO_FX% –add-modules javafx.controls StrokePolygonExample.java java –module-path %PATH_TO_FX% –add-modules javafx.controls StrokePolygonExample Output On executing, the above program generates a JavaFX window displaying a rectangle with a stroke coloured violet as shown below. Print Page Previous Next Advertisements ”;

JavaFX – Drawing an SVGPath

JavaFX – Drawing an SVGPath ”; Previous Next SVG (Scalable Vector Graphics) is an XML based language to define vector based graphics. The <path> element in the SVG library is the most powerful while drawing basic shapes. Using paths, you can draw lines, curves, arcs, and also various complex shapes including them. Even though a path is similar to the polyline element while creating complex shapes, the scale of complex shapes drawn using a polyline element is not larger than shapes drawn using path element. A path in SVG is defined by only one parameter. This parameter holds series of commands, like line, curve or arc commands. And each of these commands are instantiated using a single letter; for example, the letter ”M” calls the “Move To” command, the letter ”L” calls the “line” command and ”C” calls “Curve” command. And these letters can either be specified as either a lowercase or an uppercase letter. The lowercase letter specifies relative coordinates, while the uppercase letter specifies absolute coordinates. The same concept of SVGPath is adopted by JavaFX, in order to create objects. SVG Path in JavaFX In JavaFX we can construct images by parsing SVG paths. Such shapes are represented by the class named SVGPath. This class belongs to the package javafx.scene.shape. By instantiating this class, you can create a node which is created by parsing an SVG path in JavaFX. This class has a property named content of String datatype. This represents the SVG Path encoded string, from which the image should be drawn. To draw a shape by parsing an SVG path, you need to pass values to this property, using the method named setContent() of this class as follows − setContent(value); Steps to Draw SVGPath To Draw a shape by parsing an SVGPath in JavaFX, follow the steps given below. Step 1: Creating an Object of the SVGPath Class You can create a required shape in JavaFX by parsing an SVGPath. To do so, instantiate the class named SVGPath which belongs to a package javafx.scene.shape. You can instantiate this class inside the start() method as follows. public class ClassName extends Application { public void start(Stage primaryStage) throws Exception { //Creating an object of the class SVGPath SVGPath svgpath = new SVGPath(); } } Step 2: Setting the SVGPath Set the content for the SVG object using the method setContent(). To this method, you need to pass the SVGPath. Using which, a shape should be drawn in the form of a string as shown in the following code block. String path = “M 100 100 L 300 100 L 200 300 z”; //Setting the SVGPath in the form of string svgPath.setContent(path); Step 3: Adding SVGPath to Group In the start() method, instantiate the Group class by passing the SVGPath object as a parameter value to its constructor − Group root = new Group(svgpath); Step 4: Launching Application Once the 2D object is created, follow the given steps below to launch the application properly − Firstly, instantiate the class named Scene by passing the Group object as a parameter value to its constructor. To this constructor, you can also pass dimensions of the application screen as optional parameters. Then, set the title to the stage using the setTitle() method of the Stage class. Now, a Scene object is added to the stage using the setScene() method of the class named Stage. Display the contents of the scene using the method named show(). Lastly, the application is launched with the help of the launch() method. Example Following is a program which generates a 2D shape constructed with lines by parsing SVG path using JavaFX. Save this code in a file with the name SVGExample.java. import javafx.application.Application; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.shape.SVGPath; import javafx.stage.Stage; public class SVGExample extends Application { @Override public void start(Stage stage) { //Creating a SVGPath object SVGPath svgPath = new SVGPath(); String path = “M 100 100 L 300 100 L 200 300 z”; //Setting the SVGPath in the form of string svgPath.setContent(path); //Creating a Group object Group root = new Group(svgPath); //Creating a scene object Scene scene = new Scene(root, 600, 300); //Setting title to the Stage stage.setTitle(“Drawing a Triangle”); //Adding scene to the stage stage.setScene(scene); //Displaying the contents of the stage stage.show(); } public static void main(String args[]){ launch(args); } } Compile and execute the saved java file from the command prompt using the following commands. javac –module-path %PATH_TO_FX% –add-modules javafx.controls SVGExample.java java –module-path %PATH_TO_FX% –add-modules javafx.controls SVGExample Output On executing, the above program generates a JavaFX window displaying a triangle, which is drawn by parsing the SVG path as shown below. Example You can also construct complex shapes from curves and arcs using an SVG path. Following example creates a cubic curve using an SVG Path. Save this code in a file with the name SVGCurveExample.java. import javafx.application.Application; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.paint.Color; import javafx.scene.shape.SVGPath; import javafx.stage.Stage; public class SVGCurveExample extends Application { @Override public void start(Stage stage) { //Creating a SVGPath object SVGPath svgPath = new SVGPath(); String path = “M 70 110 C 70 180, 210 180, 210 110”; //Setting the SVGPath in the form of string svgPath.setContent(path); // Setting the stroke and fill of the path svgPath.setStroke(Color.BLACK); svgPath.setFill(Color.ORANGE); //Creating a Group object Group root = new Group(svgPath); //Creating a scene object Scene scene = new Scene(root, 300, 300); //Setting title to the Stage stage.setTitle(“Drawing a Bezier Curve”); //Adding scene to the stage stage.setScene(scene); //Displaying the contents of the stage stage.show(); } public static void main(String args[]){ launch(args); } } Compile and execute the saved java file from the command prompt using the following commands. javac –module-path %PATH_TO_FX% –add-modules javafx.controls SVGCurveExample.java java –module-path %PATH_TO_FX% –add-modules javafx.controls SVGCurveExample Output On executing, the above program generates a JavaFX window displaying a triangle, which is drawn by parsing the SVG path as shown below. Print Page Previous Next Advertisements ”;

JavaFX – Drawing Modes Property

JavaFX – Drawing Modes Property ”; Previous Next You can draw 3D shapes in a JavaFX application using the Shape3D class. This class allows you construct three types of 3D shapes: box, cylinder, sphere as its direct subclasses. However, according to the nature of a JavaFX application you are trying to create, you can also enhance the look of a 3D shape using the properties the Shape3D class provides. There are three such properties that can be applied on 3D shapes of a JavaFX application. They are listed as follows − Cull Face Property Drawing Modes Property Material Property In this chapter, we will be learning about the Drawing Modes Property in JavaFX. Drawing Modes Property Drawing Modes is the property that belongs to the DrawMode enum type and it represents the type of drawing mode used to draw the current 3D shape. In JavaFX, you can choose two draw modes to draw a 3D shape, which are − Fill − This mode draws and fills a 2D shape (DrawMode.FILL). Line − This mode draws a 3D shape using lines (DrawMode.LINE). By default, the drawing mode of a 3Dimensional shape is fill. But you can still choose the draw mode to draw a 3D shape using the method setDrawMode() as follows − box.setDrawMode(DrawMode.FILL); Example The following program is an example which demonstrates the LINE draw mode on a 3D box. Save this code in a file with the name BoxDrawModeLine.java. import javafx.application.Application; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.shape.Box; import javafx.scene.shape.DrawMode; import javafx.stage.Stage; public class BoxDrawModeLine extends Application { @Override public void start(Stage stage) { //Drawing a Box Box box1 = new Box(); //Setting the properties of the Box box1.setWidth(100.0); box1.setHeight(100.0); box1.setDepth(100.0); //Setting the position of the box box1.setTranslateX(200); box1.setTranslateY(150); box1.setTranslateZ(0); //Setting the drawing mode of the box box1.setDrawMode(DrawMode.LINE); //Creating a Group object Group root = new Group(box1); //Creating a scene object Scene scene = new Scene(root, 300, 300); //Setting title to the Stage stage.setTitle(“Drawing a Box”); //Adding scene to the stage stage.setScene(scene); //Displaying the contents of the stage stage.show(); } public static void main(String args[]){ launch(args); } } Compile and execute the saved java file from the command prompt using the following commands. javac –module-path %PATH_TO_FX% –add-modules javafx.controls BoxDrawModeLine.java java –module-path %PATH_TO_FX% –add-modules javafx.controls BoxDrawModeLine Output On executing, the above program generates a JavaFX window displaying a box with draw mode LINE, as follows − Example Let us now see another example that shows the usage of FILL draw mode on a 3D shape. To show the difference of these modes properly, we will again apply this mode on a 3D box. Save this code in a file with the name BoxDrawModeFill.java. import javafx.application.Application; import javafx.scene.Group; import javafx.scene.PerspectiveCamera; import javafx.scene.Scene; import javafx.scene.shape.Box; import javafx.scene.shape.DrawMode; import javafx.stage.Stage; public class BoxDrawModeFill extends Application { @Override public void start(Stage stage) { //Drawing a Box Box box1 = new Box(); //Setting the properties of the Box box1.setWidth(100.0); box1.setHeight(100.0); box1.setDepth(100.0); //Setting the position of the box box1.setTranslateX(200); box1.setTranslateY(150); box1.setTranslateZ(0); //Setting the drawing mode of the box box1.setDrawMode(DrawMode.FILL); //Creating a Group object Group root = new Group(box1); //Creating a scene object Scene scene = new Scene(root, 600, 300); //Setting camera PerspectiveCamera camera = new PerspectiveCamera(false); camera.setTranslateX(100); camera.setTranslateY(50); camera.setTranslateZ(0); scene.setCamera(camera); //Setting title to the Stage stage.setTitle(“Drawing a Box”); //Adding scene to the stage stage.setScene(scene); //Displaying the contents of the stage stage.show(); } public static void main(String args[]){ launch(args); } } Compile and execute the saved java file from the command prompt using the following commands. javac –module-path %PATH_TO_FX% –add-modules javafx.controls BoxDrawModeFill.java java –module-path %PATH_TO_FX% –add-modules javafx.controls BoxDrawModeFill Output On executing, the above program generates a JavaFX window displaying a box with draw mode FILL, as follows − Print Page Previous Next Advertisements ”;

JavaFX – Fade Transition

JavaFX – Fade Transition ”; Previous Next A Fade transition is a type of a geometrical transition that changes the opacity property of an object. Using fade transition, you can either reduce the opacity of the object or increase it. This transition is known as a geometrical transition as it deals with the geometry of an object. In JavaFX, the fade transition is used to transition a node”s opacity from a starting value to an ending value over a specified duration. This can be done using the FadeTransition class belonging to the javafx.animation package. Fade Transition in JavaFX You can apply the fade transition to a JavaFX object using the FadeTransition class properties. You have to set the starting value and ending value of the transition using fromValue and toValue. When fromValue is not specified, the node”s current opacity value is considered by default; and when toValue is not specified, the byValue is added to the starting value. Note that Transition properties − fromValue, toValue and byValue, cannot be changed while a transition is running. However, if you attempt to change a property while the transition is running, the change is ignored. Hence, the animation must be stopped and restarted to assign the new property value(s) to the transition. No exception is thrown either. The FadeTransition class contains the following properties − byValue − Specifies the incremented stop opacity value, from the start, of this FadeTransition. duration − The duration of this FadeTransition. fromValue − Specifies the start opacity value for this FadeTransition. node − The target node of this Transition. toValue − Specifies the stop opacity value for this FadeTransition. Example Following is the program which demonstrates Fade Transition in JavaFX. Save this code in a file with the name FadeTransitionExample.java. import javafx.animation.FadeTransition; import javafx.application.Application; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.paint.Color; import javafx.scene.shape.Circle; import javafx.stage.Stage; import javafx.util.Duration; public class FadeTransitionExample extends Application { @Override public void start(Stage stage) { //Drawing a Circle Circle circle = new Circle(); //Setting the position of the circle circle.setCenterX(300.0f); circle.setCenterY(135.0f); //Setting the radius of the circle circle.setRadius(100.0f); //Setting the color of the circle circle.setFill(Color.BROWN); //Setting the stroke width of the circle circle.setStrokeWidth(20); //Creating the fade Transition FadeTransition fadeTransition = new FadeTransition(Duration.millis(1000)); //Setting the node for Transition fadeTransition.setNode(circle); //Setting the property fromValue of the transition (opacity) fadeTransition.setFromValue(1.0); //Setting the property toValue of the transition (opacity) fadeTransition.setToValue(0.3); //Setting the cycle count for the transition fadeTransition.setCycleCount(50); //Setting auto reverse value to false fadeTransition.setAutoReverse(false); //Playing the animation fadeTransition.play(); //Creating a Group object Group root = new Group(circle); //Creating a scene object Scene scene = new Scene(root, 600, 300); //Setting title to the Stage stage.setTitle(“Fade transition example”); //Adding scene to the stage stage.setScene(scene); //Displaying the contents of the stage stage.show(); } public static void main(String args[]){ launch(args); } } Compile and execute the saved java file from the command prompt using the following commands. javac –module-path %PATH_TO_FX% –add-modules javafx.controls FadeTransitionExample.java java –module-path %PATH_TO_FX% –add-modules javafx.controls FadeTransitionExample Output On executing, the above program generates a JavaFX window as shown below. Print Page Previous Next Advertisements ”;

JavaFX – Drawing a Polyline

JavaFX – Drawing a Polyline ”; Previous Next Polyline is defined as a continuous structure that is formed by combining multiple line segments with some vertices. These vertices are addressed as endpoints. Thus, a polyline can be constructed by specifying these endpoints through which these line segments are to be drawn. It consists of various properties like Points, width, color, start and end caps, type of join, stroke pattern etc. A Polyline is same as a polygon except that a polyline is not closed in the end. Or, continuous line composed of one or more line segments. In short, we can say a polygon is an open figure formed by coplanar line segments. Polyline in JavaFX In JavaFX, a Polyline is represented by a class named Polygon. This class belongs to the package javafx.scene.shape.. By instantiating this class, you can create polyline node in JavaFX. You need to pass the x, y coordinates of the points by which the polyline should be defined in the form of a double array. You can pass the double array as a parameter of the constructor of this class as shown below − Polyline polyline = new Polyline(doubleArray); Or, by using the getPoints() method as follows − polyline.getPoints().addAll(new Double[]{List of XY coordinates separated by commas }); Steps to Draw Polyline To Draw a Polyline in JavaFX, follow the steps given below. Step 1: Creating a Polyline You can create a line in JavaFX by instantiating the class named Line which belongs to a package javafx.scene.shape. You can instantiate this class in start() method as follows. public class ClassName extends Application { @Override public void start(Stage primaryStage) throws Exception { //Creating an object of the class Polyline Polyline polyline = new Polyline(); } } Step 2: Setting Properties to the Polyline Specify a double array holding the XY coordinates of the points of the required polyline (hexagon in this example) separated by commas. You can do this by using the getPoints() method of the Polyline class as shown in the following code block. //Adding coordinates to the hexagon polyline.getPoints().addAll(new Double[]{ 200.0, 50.0, 400.0, 50.0, 450.0, 150.0, 400.0, 250.0, 200.0, 250.0, 150.0, 150.0, }); Step 3: Adding Polyline Object to Group In the start() method, instantiate the class named Group, which belongs to the package javafx.scene, by passing the Polyline object, created in the previous step, as a parameter value to its constructor. Group root = new Group(polyline); Step 4: Launching Application Once the 2D object is created, follow the given steps below to launch the application properly − Firstly, instantiate the class named Scene by passing the Group object as a parameter value to its constructor. To this constructor, you can also pass dimensions of the application screen as optional parameters. Then, set the title to the stage using the setTitle() method of the Stage class. Now, a Scene object is added to the stage using the setScene() method of the class named Stage. Display the contents of the scene using the method named show(). Lastly, the application is launched with the help of the launch() method. Example Following is a program which generates a polyline using JavaFX. Save this code in a file with the name PolylineExample1.java. import javafx.application.Application; import javafx.scene.Group; import javafx.scene.Scene; import javafx.stage.Stage; import javafx.scene.shape.Polyline public class PolylineExample1 extends Application { @Override public void start(Stage stage) { //Creating a polyline Polyline polyline = new Polyline(); //Adding coordinates to the polygon polyline.getPoints().addAll(new Double[]{ 200.0, 50.0, 400.0, 50.0, 450.0, 150.0, 400.0, 250.0, 200.0, 250.0, 150.0, 150.0, }); //Creating a Group object Group root = new Group(polyline); //Creating a scene object Scene scene = new Scene(root, 600, 300); //Setting title to the Stage stage.setTitle(“Drawing a Polyline”); //Adding scene to the stage stage.setScene(scene); //Displaying the contents of the stage stage.show(); } public static void main(String args[]){ launch(args); } } Compile and execute the saved java file from the command prompt using the following commands. javac –module-path %PATH_TO_FX% –add-modules javafx.controls PolylineExample1.java java –module-path %PATH_TO_FX% –add-modules javafx.controls PolylineExample1 Output On executing, the above program generates a JavaFX window displaying a polyline as shown below. Example In this example, let us try to draw a polyline of 4 vertices. You can save the file name as PolylineExample2.java. import javafx.application.Application; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.shape.Polyline; import javafx.stage.Stage; public class PolylineExample2 extends Application { @Override public void start(Stage stage) { //Creating a Polyline Polyline polyline = new Polyline(); //Adding coordinates to the polygon polyline.getPoints().addAll(new Double[]{ 300.0, 50.0, 450.0, 150.0, 300.0, 250.0, 150.0, 150.0, }); //Creating a Group object Group root = new Group(polyline); //Creating a scene object Scene scene = new Scene(root, 600, 300); //Setting title to the Stage stage.setTitle(“Drawing a Polyline”); //Adding scene to the stage stage.setScene(scene); //Displaying the contents of the stage stage.show(); } public static void main(String args[]){ launch(args); } } Compile and execute the saved java file from the command prompt using the following commands. javac –module-path %PATH_TO_FX% –add-modules javafx.controls PolylineExample2.java java –module-path %PATH_TO_FX% –add-modules javafx.controls PolylineExample2 Output On executing, the above program generates a JavaFX window displaying a 4 vertices Polyline as shown below. Print Page Previous Next Advertisements ”;

JavaFX – Path Transition

JavaFX – Path Transition ”; Previous Next A path transition in JavaFX is used to move a JavaFX node (or object) around a specific path. This is similar to translate transition, as it also moves the object from one position to another. However, the translate transition does not provide a continuous path through which the object moves; which path transition does. Any JavaFX node, like a 2D or 3D shape, text, image etc., can be moved along any path: straight or curved. Path Transition in JavaFX JavaFX offers a PathTransition class to apply the path transition on a JavaFX node. This class belongs to the javafx.animation package. This Transition creates a path animation that moves an object in a certain path and spans its duration. Path transition does nothing but translate an object in order to relocate it. This translation along a path is done by updating the coordinates of the node in both X and Y directions, and by updating the orientation to OrientationType.ORTHOGONAL_TO_TANGENT, at regular interval. The animated path is defined by the outline of any JavaFX shape. The PathTransition class offers the following properties to be applied on a node − duration − The duration of this Transition. node − The target node of this PathTransition. orientation − Specifies the upright orientation of node along the path. path − The shape on which outline the node should be animated. Example 1 Following is the program which demonstrates Path Transition in JavaFX. Save this code in a file with the name PathTransitionExample.java. import javafx.animation.PathTransition; import javafx.application.Application; import static javafx.application.Application.launch; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.paint.Color; import javafx.scene.shape.Circle; import javafx.scene.shape.CubicCurveTo; import javafx.scene.shape.MoveTo; import javafx.scene.shape.Path; import javafx.stage.Stage; import javafx.util.Duration; public class PathTransitionExample extends Application { @Override public void start(Stage stage) { //Drawing a Circle Circle circle = new Circle(); //Setting the position of the circle circle.setCenterX(300.0f); circle.setCenterY(135.0f); //Setting the radius of the circle circle.setRadius(25.0f); //Setting the color of the circle circle.setFill(Color.BROWN); //Setting the stroke width of the circle circle.setStrokeWidth(20); //Instantiating the path class Path path = new Path(); //Creating the MoveTo path element MoveTo moveTo = new MoveTo(100, 150); //Creating the Cubic curve path element CubicCurveTo cubicCurveTo = new CubicCurveTo(400, 40, 175, 250, 500, 150); //Adding the path elements to Observable list of the Path class path.getElements().add(moveTo); path.getElements().add(cubicCurveTo); //Creating a path transition PathTransition pathTransition = new PathTransition(); //Setting the duration of the path transition pathTransition.setDuration(Duration.millis(1000)); //Setting the node for the transition pathTransition.setNode(circle); //Setting the path pathTransition.setPath(path); //Setting the orientation of the path pathTransition.setOrientation(PathTransition.OrientationType. ORTHOGONAL_TO_TAN GENT); //Setting the cycle count for the transition pathTransition.setCycleCount(50); //Setting auto reverse value to false pathTransition.setAutoReverse(false); //Playing the animation pathTransition.play(); //Creating a Group object Group root = new Group(circle); //Creating a scene object Scene scene = new Scene(root, 600, 300); //Setting title to the Stage stage.setTitle(“Path transition example”); //Adding scene to the stage stage.setScene(scene); //Displaying the contents of the stage stage.show(); } public static void main(String args[]){ launch(args); } } Compile and execute the saved java file from the command prompt using the following commands. javac –module-path %PATH_TO_FX% –add-modules javafx.controls PathTransitionExample.java java –module-path %PATH_TO_FX% –add-modules javafx.controls PathTransitionExample Output On executing, the above program generates a JavaFX window as shown below. Example 2 Following is an example which transforms a circle along a complex path. Save this code in a file with name PathTransitionExample2.java. import javafx.animation.PathTransition; import javafx.application.Application; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.paint.Color; import javafx.scene.shape.Circle; import javafx.scene.shape.LineTo; import javafx.scene.shape.MoveTo; import javafx.scene.shape.Path; import javafx.stage.Stage; import javafx.util.Duration; public class PathTransitionExample2 extends Application { @Override public void start(Stage stage) { //Drawing a Circle Circle circle = new Circle(); //Setting the position of the circle circle.setCenterX(300.0f); circle.setCenterY(135.0f); //Setting the radius of the circle circle.setRadius(25.0f); //Setting the color of the circle circle.setFill(Color.BROWN); //Setting the stroke width of the circle circle.setStrokeWidth(20); //Creating a Path Path path = new Path(); //Moving to the starting point MoveTo moveTo = new MoveTo(108, 71); //Creating 1st line LineTo line1 = new LineTo(321, 161); //Creating 2nd line LineTo line2 = new LineTo(126,232); //Creating 3rd line LineTo line3 = new LineTo(232,52); //Creating 4th line LineTo line4 = new LineTo(269, 250); //Creating 5th line LineTo line5 = new LineTo(108, 71); //Adding all the elements to the path path.getElements().add(moveTo); path.getElements().addAll(line1, line2, line3, line4, line5); //Creating the path transition PathTransition pathTransition = new PathTransition(); //Setting the duration of the transition pathTransition.setDuration(Duration.millis(1000)); //Setting the node for the transition pathTransition.setNode(circle); //Setting the path for the transition pathTransition.setPath(path); //Setting the orientation of the path pathTransition.setOrientation( PathTransition.OrientationType.ORTHOGONAL_TO_TAN GENT); //Setting the cycle count for the transition pathTransition.setCycleCount(50); //Setting auto reverse value to true pathTransition.setAutoReverse(false); //Playing the animation pathTransition.play(); //Creating a Group object Group root = new Group(circle); //Creating a scene object Scene scene = new Scene(root, 600, 300); //Setting title to the Stage stage.setTitle(“Path transition example”); //Adding scene to the stage stage.setScene(scene); //Displaying the contents of the stage stage.show(); } public static void main(String args[]){ launch(args); } } Compile and execute the saved java file from the command prompt using the following commands. javac –module-path %PATH_TO_FX% –add-modules javafx.controls PathTransitionExample2.java java –module-path %PATH_TO_FX% –add-modules javafx.controls PathTransitionExample2 Output On executing, the above program generates a JavaFX window as shown below. Print Page Previous Next Advertisements ”;

JavaFX – Drawing a Quad Curve

JavaFX – Drawing a Quad Curve ”; Previous Next Mathematically, a quadratic curve is one that is described by a quadratic function like − y = ax2 + bx + c. In computer graphics Bezier curves are used. These are parametric curves which appear reasonably smooth at all scales. These Bezier curves are drawn based on points on an XY plane. A quadratic curve is a Bezier parametric curve in the XY plane which is a curve of degree 2. It is drawn using three points: start point, end point and control point as shown in the following diagram Quad Curve in JavaFX In JavaFX, a Quad Curve is represented by a class named QuadCurve. This class belongs to the package javafx.scene.shape. By instantiating this class, you can create a QuadCurve node in JavaFX. This class has 6 properties of the double datatype namely − startX − The x coordinate of the starting point of the curve. startY − The y coordinate of the starting point of the curve. controlX − The x coordinate of the control point of the curve. controlY − The y coordinate of the control point of the curve. endX − The x coordinate of the end point of the curve. endY − The y coordinate of the end point of the curve. To draw a Quad Curve, you need to pass values to these properties. This can be done either by passing them to the constructor of this class, in the same order, at the time of instantiation; or by using appropriate setter methods. Steps to Draw Quad Curve To Draw a Bezier Quadrilateral Curve in JavaFX, follow the steps given below. Step 1: Creating a Quad Curve You can create a Quad Curve in JavaFX by instantiating the class named QuadCurve which belongs to a package javafx.scene.shape. You can then instantiate this class in start() method of Application class as shown in the following code block. public class ClassName extends Application { public void start(Stage primaryStage) throws Exception { //Creating an object of the class QuadCurve QuadCurve quadcurve = new QuadCurve(); } } Step 2: Setting Properties to the Quad Curve Specify the x, y coordinates of the three points: start point, end point and control points, of the required curve, using their respective setter methods as shown in the following code block. //Adding properties to the Quad Curve quadCurve.setStartX(100.0); quadCurve.setStartY(220.0f); quadCurve.setEndX(500.0f); quadCurve.setEndY(220.0f); quadCurve.setControlX(250.0f); quadCurve.setControlY(0.0f); Or, by using their respective setter methods as follows − QuadCurve quadcurve = new QuadCurve(startX, startY, controlX, controlY, endX, endY); Step 3: Adding Quad Curve Object to Group In the start() method, instantiate a Group class by passing the previously created QuadCurve object as a parameter value to its constructor − Group root = new Group(quadcurve); Step 4: Launching Application Once the 2D object is created, follow the given steps below to launch the application properly − Firstly, instantiate the class named Scene by passing the Group object as a parameter value to its constructor. To this constructor, you can also pass dimensions of the application screen as optional parameters. Then, set the title to the stage using the setTitle() method of the Stage class. Now, a Scene object is added to the stage using the setScene() method of the class named Stage. Display the contents of the scene using the method named show(). Lastly, the application is launched with the help of the launch() method. Example Following is a program which generates a quadrilateral curve using JavaFX. Save this code in a file with the name QuadCurveExample.java. import javafx.application.Application; import javafx.scene.Group; import javafx.scene.Scene; import javafx.stage.Stage; import javafx.scene.shape.QuadCurve; public class QuadCurveExample extends Application { @Override public void start(Stage stage) { //Creating a QuadCurve QuadCurve quadCurve = new QuadCurve(); //Adding properties to the Quad Curve quadCurve.setStartX(100.0); quadCurve.setStartY(220.0f); quadCurve.setEndX(500.0f); quadCurve.setEndY(220.0f); quadCurve.setControlX(250.0f); quadCurve.setControlY(0.0f); //Creating a Group object Group root = new Group(quadCurve); //Creating a scene object Scene scene = new Scene(root, 600, 300); //Setting title to the Stage stage.setTitle(“Drawing a Quad curve”); //Adding scene to the stage stage.setScene(scene); //Displaying the contents of the stage stage.show(); } public static void main(String args[]){ launch(args); } } Compile and execute the saved java file from the command prompt using the following commands. javac –module-path %PATH_TO_FX% –add-modules javafx.controls QuadCurveExample.java java –module-path %PATH_TO_FX% –add-modules javafx.controls QuadCurveExample Output On executing, the above program generates a JavaFX window displaying a Bezier quadrilateral curve as shown in the following screenshot. Example Now, you can also draw this quadrilateral curve by applying any effect, say bloom effect, as shown in the example below. Save the code in a file named QuadCurveEffect.java. import javafx.application.Application; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.effect.Bloom; import javafx.stage.Stage; import javafx.scene.paint.Color; import javafx.scene.shape.QuadCurve; public class QuadCurveEffect extends Application { @Override public void start(Stage stage) { //Creating a QuadCurve QuadCurve quadCurve = new QuadCurve(); //Adding properties to the Quad Curve quadCurve.setStartX(100.0); quadCurve.setStartY(220.0f); quadCurve.setEndX(300.0f); quadCurve.setEndY(220.0f); quadCurve.setControlX(250.0f); quadCurve.setControlY(0.0f); quadCurve.setFill(Color.RED); //Instantiating the Bloom class Bloom bloom = new Bloom(); //setting threshold for bloom bloom.setThreshold(0.1); //Applying bloom effect to quadCurve quadCurve.setEffect(bloom); //Creating a Group object Group root = new Group(quadCurve); //Creating a scene object Scene scene = new Scene(root, 400, 300); //Setting title to the Stage stage.setTitle(“Drawing a Quad curve”); //Adding scene to the stage stage.setScene(scene); //Displaying the contents of the stage stage.show(); } public static void main(String args[]){ launch(args); } } Compile and execute the saved java file from the command prompt using the following commands. javac –module-path %PATH_TO_FX% –add-modules javafx.controls QuadCurveEffect.java java –module-path %PATH_TO_FX% –add-modules javafx.controls QuadCurveEffect Output On executing, the above program generates a JavaFX window displaying a Bezier quadrilateral curve as shown in the following screenshot. Print Page Previous Next Advertisements ”;