Here are the various geometric shapes you can draw using JavaFX
Line - A line is a geometric structure that connects two points. javafx.scene.shape. Line Class represents a line in the XY plane.
-
Rectangle - A rectangle is a four-sided polygon with two pairs of parallel and concurrent sides, and all interior angles are right angles. javafx.scene. Rectangle Class represents a rectangle in the XY plane.
Circle strong> - A circle is a line forming a closed loop, with each point on it being a fixed distance from the center point. javafx.scene. Circle Class represents a circle in the XY plane.
Ellipse strong> - An ellipse is defined by two points, each called a focus. If you take any point on the ellipse, the sum of the distances to the focus is constant. The class of javafx.scene.Ellipse represents an ellipse in the XY plane.
Polygon > - A closed shape formed by many coplanar line segments connected end to end is called a polygon. The javafx.scene.Polygon class represents polygons in the XY plane.
Polyline - A polyline is the same as a polygon, except that the polyline is not closed at the end. Or, a continuous line consisting of one or more line segments. The javafx.scene.Polyline class represents a polyline in the XY plane.
Cubic curve strong> - A cubic curve is a Bezier parametric curve in the XY plane and is a cubic curve. javafx.scene.CubicCurve Class represents a cubic curve in XY
QuadCurve - A quadratic curve is the XY plane The Bezier parameter curve in is a quadratic curve. The javafx.scene.QuadCurve class represents a quadrilateral curve in the XY plane.
Arc - An arc is a portion of a curve. The javafx.scene.Arc class represents an arc in the XY plane.
To create the desired shape you need to instantiate the appropriate class.
Set its properties.
-
Add the created object to the group.
li> Examples
The following JavaFX examples demonstrate the creation of all available 2D shapes-
import javafx.application.Application; import javafx.scene.Group; import javafx.scene.Scene; import javafx.stage.Stage; import javafx.scene.shape.Arc; import javafx.scene.shape.ArcType; import javafx.scene.shape.Circle; import javafx.scene.shape.CubicCurve; import javafx.scene.shape.Ellipse; import javafx.scene.shape.Line; import javafx.scene.shape.Polygon; import javafx.scene.shape.Polyline; import javafx.scene.shape.QuadCurve; import javafx.scene.shape.Rectangle; import javafx.scene.text.Font; import javafx.scene.text.FontPosture; import javafx.scene.text.FontWeight; import javafx.scene.text.Text; public class JavaFXShapes extends Application { public void start(Stage stage) { Font font = Font.font("verdana", FontWeight.BOLD, FontPosture.REGULAR, 12); Text cirText = new Text("Circle"); cirText.setFont(font); cirText.setX(50); cirText.setY(130); Text rectText = new Text("Rectangle"); rectText.setFont(font); rectText.setX(170); rectText.setY(130); Text ellipseText = new Text("Ellipse"); ellipseText.setFont(font); ellipseText.setX(310); ellipseText.setY(130); Text polyText = new Text("Polygon"); polyText.setFont(font); polyText.setX(425); polyText.setY(130); Text lineText = new Text("Line"); lineText.setFont(font); lineText.setX(530); lineText.setY(130); Text polyLineText = new Text("Poly Line"); polyLineText.setFont(font); polyLineText.setX(40); polyLineText.setY(260); Text cubicCurveText = new Text("Cubic Curve"); cubicCurveText.setFont(font); cubicCurveText.setX(140); cubicCurveText.setY(260); Text quadCurveText = new Text("Quad Curve"); quadCurveText.setFont(font); quadCurveText.setX(340); quadCurveText.setY(260); Text arcText = new Text("Arc"); arcText.setFont(font); arcText.setX(490); arcText.setY(260); //Drawing a circle Circle circle = new Circle(75.0f, 65.0f, 40.0f ); //Drawing a Rectangle Rectangle rect = new Rectangle(150, 30, 100, 65); //Drawing an ellipse Ellipse ellipse = new Ellipse(330, 60, 60, 35); //Drawing Polygon Polygon poly = new Polygon(410, 60, 430, 30, 470, 30, 490, 60, 470, 100, 430, 100 ); //Drawing a Line Line line = new Line(540, 30, 540, 90); line.setStrokeWidth(5.0); //Drawing a Poly line Polyline polyLine = new Polyline(25, 210, 100, 210, 50, 180, 50, 230); polyLine.setStrokeWidth(5.0); //Drawing a cubic curve CubicCurve cubicCurve = new CubicCurve(150.0, 210.0, 200.0, 70.0, 200.0, 290.0, 270.0, 210.0); //Drawing Quadratic curve QuadCurve quadCurve = new QuadCurve(400.0, 200.0, 440.0, 250.0, 330.0, 170.0); //Drawing an arc Arc arc = new Arc(490, 240, 50, 80, 30, 70); arc.setType(ArcType.ROUND); //Setting the stage Group root = new Group( circle, ellipse, rect, poly, line, polyLine, cubicCurve, quadCurve, arc, cirText, rectText, ellipseText, polyText, lineText, polyLineText, cubicCurveText, quadCurveText, arcText); Scene scene = new Scene(root, 600, 300); stage.setTitle("2D shapes Example"); stage.setScene(scene); stage.show(); } public static void main(String args[]){ launch(args); } }
The above is the detailed content of What are the various 2D shapes provided by JavaFX?. For more information, please follow other related articles on the PHP Chinese website!

The article discusses using Maven and Gradle for Java project management, build automation, and dependency resolution, comparing their approaches and optimization strategies.

The article discusses creating and using custom Java libraries (JAR files) with proper versioning and dependency management, using tools like Maven and Gradle.

The article discusses implementing multi-level caching in Java using Caffeine and Guava Cache to enhance application performance. It covers setup, integration, and performance benefits, along with configuration and eviction policy management best pra

The article discusses using JPA for object-relational mapping with advanced features like caching and lazy loading. It covers setup, entity mapping, and best practices for optimizing performance while highlighting potential pitfalls.[159 characters]

Java's classloading involves loading, linking, and initializing classes using a hierarchical system with Bootstrap, Extension, and Application classloaders. The parent delegation model ensures core classes are loaded first, affecting custom class loa


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Dreamweaver Mac version
Visual web development tools

Dreamweaver CS6
Visual web development tools