Polyline is part of the JavaFX library. Polyline is a set of connected points. Though Polyline is almost similar to the Polygon class, the only difference is polygon forms a closed area whereas the Polyline can form both closed and open area. Also, Polyline class extends shape class.
Constructors for class are:
- Polyline():Creates an empty instance of Polyline.
- Polyline(double… points): creates a new instance of polyline with given points
Commonly used methods:
| method | explanation |
|---|---|
| getPoints() | gets the points of the polyline segments |
| toString() | Returns a string representation of this Polyline object. |
Below programs illustrate the use of Polyline:
- Program to create an open area of connected segments using polyline: This program creates a Polyline indicated by the name polyline( the coordinates of the points of the line segments to create an open area). The Polyline 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 polyline 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 open area// of connected segments using polylineimportjavafx.application.Application;importjavafx.scene.Scene;importjavafx.scene.control.Button;importjavafx.scene.layout.*;importjavafx.scene.paint.Color;importjavafx.scene.shape.Polyline;importjavafx.scene.control.*;importjavafx.stage.Stage;importjavafx.scene.Group;publicclassPolyline_0extendsApplication {// launch the applicationpublicvoidstart(Stage stage){// set title for the stagestage.setTitle("creating Polyline");// pointsdoublepoints[] = {20.0d,20.0d,40.0d,240.0d,60.0d,180.0d,80.0d,200.0d,100.0d,90.0d };// create a polylinePolyline polyline =newPolyline(points);// create a GroupGroup group =newGroup(polyline);// create a sceneScene scene =newScene(group,500,300);// set the scenestage.setScene(scene);stage.show();}publicstaticvoidmain(String args[]){// launch the applicationlaunch(args);}}chevron_rightfilter_noneOutput:

- Program to create a closed area of connected segments using polyline: This program creates a Polyline indicated by the name polyline( the coordinates of the points of the line segments to create a closed area). The Polyline 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 polyline 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 closed area// of connected segments using polylineimportjavafx.application.Application;importjavafx.scene.Scene;importjavafx.scene.control.Button;importjavafx.scene.layout.*;importjavafx.scene.paint.Color;importjavafx.scene.shape.Polyline;importjavafx.scene.control.*;importjavafx.stage.Stage;importjavafx.scene.Group;publicclassPolyline_1extendsApplication {// launch the applicationpublicvoidstart(Stage stage){// set title for the stagestage.setTitle("creating Polyline");// pointsdoublepoints[] = {20.0d,20.0d,40.0d,240.0d,60.0d,180.0d,80.0d,200.0d,100.0d,90.0d,20.0d,20.0d };// create a polylinePolyline polyline =newPolyline(points);// create a GroupGroup group =newGroup(polyline);// create a sceneScene scene =newScene(group,500,300);// set the scenestage.setScene(scene);stage.show();}publicstaticvoidmain(String args[]){// launch the applicationlaunch(args);}}chevron_rightfilter_noneOutput:

- JavaFX | Arc with examples
- JavaFX | Box with examples
- JavaFX | CubicCurve with examples
- JavaFX | Line with examples
- JavaFX | ContextMenu with examples
- JavaFX | Button with examples
- JavaFX | Ellipse with examples
- JavaFX | QuadCurve with examples
- JavaFX | RadioButton with examples
- JavaFX | Sphere with examples
- JavaFX | Cylinder with examples
- JavaFx | ColorPicker with examples
- JavaFX | DatePicker with examples
- JavaFX | Alert with examples
- JavaFX | ComboBox with examples
- JavaFX | Polygon with examples
- JavaFX | PointLight with examples
- JavaFX | CheckMenuItem with examples
- JavaFX | Circle with examples
- JavaFX | Cursor class with examples
Note :The above programs might not run in an online IDE please use an offline converter.
Reference:https://docs.oracle.com/javase/8/javafx/api/javafx/scene/shape/Polyline.html
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
Recommended Posts:
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : ManasChhabra2

