- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to Create the path element arc in JavaFX?
This is class represents the path element arc. It helps you to draw an arc from the current coordinates to the specified (new) coordinates.
To create a line path element −
Instantiate the ArcTo class.
Set values to the properties of this class using setter methods or, bypassing them to the constructor.
Instantiate the Path class.
Get the observable list object of the above-created Path using the getElements() method.
Add the above created ArcTo object to the observable list using the add() method.
Finally, add the path to the Group object.
Example
import javafx.application.Application; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.paint.Color; import javafx.stage.Stage; import javafx.scene.shape.ArcTo; import javafx.scene.shape.LineTo; import javafx.scene.shape.MoveTo; import javafx.scene.shape.Path; import javafx.scene.shape.VLineTo; public class ArcToExample extends Application { public void start(Stage stage) { //Creating PathElement objects MoveTo moveTo = new MoveTo(490, 50); LineTo line1 = new LineTo(250, 250); //Instantiating the arcTo class ArcTo arcTo = new ArcTo(); arcTo.setX(300.0); arcTo.setY(50.0); arcTo.setRadiusX(50.0); arcTo.setRadiusY(50.0); //Creating the HLineTo object VLineTo vLine = new VLineTo(); vLine.setY(180); //Creating a Path Path path = new Path(); path.getElements().addAll(moveTo, line1, arcTo, vLine); //Setting other properties path.setStrokeWidth(8.0); path.setStroke(Color.DARKSLATEGREY); //Preparing the Stage object Group root = new Group(path); Scene scene = new Scene(root, 595, 300, Color.BEIGE); stage.setTitle("JavaFX Example"); stage.setScene(scene); stage.show(); } public static void main(String args[]){ launch(args); } }
Output
Advertisements