Home Java javaTutorial What are the various 2D shapes provided by JavaFX?

What are the various 2D shapes provided by JavaFX?

Sep 03, 2023 pm 09:41 PM
javafx d shape shape

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-

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

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);

   }

}

Copy after login

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!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What are the various 2D shapes provided by JavaFX? What are the various 2D shapes provided by JavaFX? Sep 03, 2023 pm 09:41 PM

Below are the various geometric shapes you can draw using JavaFX Lines - A line is a geometric structure that connects two points. javafx.scene.shape. The 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. The Rectangle class represents a rectangle in the XY plane. Circle - A circle is a line forming a closed loop, with each point on it being a fixed distance from the center point. javafx.scene. The Circle class represents a circle in the XY plane. Ellipse - An ellipse is defined by two points, each point is called a focus. If you take any point on the ellipse, the sum of the distances to the focus

Display web content using the new JavaFX WebView component in Java 13 Display web content using the new JavaFX WebView component in Java 13 Aug 01, 2023 pm 01:09 PM

Use the new JavaFXWebView component in Java13 to display web content. With the continuous development of Java, JavaFX has become one of the main tools for building cross-platform graphical interfaces. JavaFX provides a wealth of graphics libraries and components, allowing developers to easily create a variety of user interfaces. Among them, the JavaFXWebView component is a very useful component that allows us to display web content in JavaFX applications. In Java13, J

Java Error: JavaFX View Error, How to Handle and Avoid Java Error: JavaFX View Error, How to Handle and Avoid Jun 25, 2023 am 08:47 AM

JavaFX is a user interface framework for the Java platform, similar to Swing, but more modern and flexible. However, you may encounter some view errors when using it. This article will introduce how to deal with and avoid these errors. 1. Types of JavaFX view errors When using JavaFX, you may encounter the following view errors: NullPointerException This is one of the most common errors and usually occurs when trying to access an uninitialized or non-existent object. This may

Build desktop applications using Spring Boot and JavaFX Build desktop applications using Spring Boot and JavaFX Jun 22, 2023 am 10:55 AM

As technology continues to evolve, we can now use different technologies to build desktop applications. SpringBoot and JavaFX are one of the more popular choices now. This article will focus on how to use these two frameworks to build a feature-rich desktop application. 1. Introduction to SpringBoot and JavaFXSpringBoot is a rapid development framework based on the Spring framework. It helps developers quickly build web applications while providing a set of

How to implement a graphical interface for real-time communication using JavaFX and WebSocket in Java 9 How to implement a graphical interface for real-time communication using JavaFX and WebSocket in Java 9 Jul 30, 2023 pm 04:57 PM

How to use JavaFX and WebSocket to implement a graphical interface for real-time communication in Java9 Introduction: With the development of the Internet, the need for real-time communication is becoming more and more common. In Java9, we can use JavaFX and WebSocket technology to implement real-time communication applications with graphical interfaces. This article will introduce how to use JavaFX and WebSocket technology to implement a graphical interface for real-time communication in Java9, and attach corresponding code examples. Part One: Ja

Java Error: JavaFX graphics errors, how to deal with and avoid them Java Error: JavaFX graphics errors, how to deal with and avoid them Jun 25, 2023 am 10:48 AM

JavaFX is a framework for building rich client applications, but during use, you may encounter some JavaFX graphics errors, which will affect the normal operation of the application. This article explains how to deal with and avoid JavaFX graphics errors. 1. Types of JavaFX graphics errors There are many types of JavaFX graphics errors, including the following aspects: 1. Thread error: JavaFX needs to be executed on the UI thread. If the JavaFX code is executed on the background thread, a thread error will occur.

How to use JavaFX to build responsive UI interfaces in Java 9 How to use JavaFX to build responsive UI interfaces in Java 9 Jul 30, 2023 pm 06:36 PM

How to use JavaFX to build a responsive UI interface in Java9 Introduction: In the development process of computer applications, the user interface (UI) is a very important part. A good UI can improve the user experience and make the application more attractive. JavaFX is a graphical user interface (GUI) framework on the Java platform. It provides a rich set of tools and APIs to quickly build interactive UI interfaces. In Java 9, JavaFX has become a JavaSE

Beautify your user interface with new JavaFX CSS stylesheets in Java 13 Beautify your user interface with new JavaFX CSS stylesheets in Java 13 Jul 30, 2023 pm 02:49 PM

Use the new JavaFXCSS style sheet in Java13 to beautify the user interface Introduction: In software development, the beauty and ease of use of the user interface are crucial to improving the user experience. JavaFX is a modern, expressive interface technology on the Java platform that provides rich UI components and functions. In order to make the user interface more beautiful, JavaFX provides CSS style sheets to beautify and customize the interface. In Java13, JavaFX introduced new CSS style sheets,

See all articles