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.LineClass 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.RectangleClass 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.CircleClass 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. Theclass 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.Polylineclass 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.CubicCurveClass 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.QuadCurveclass represents a quadrilateral curve in the XY plane.
Arc- An arc is a portion of a curve. The javafx.scene.Arcclass 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
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!