Java Swing: drawing curved lines

I am trying to draw curved lines in Java. A simple Bezier curve with start (X, Y), end (X, Y) and the amount of the curve will be enough.

I cannot find a way to do this in Swing. If it's not in Swing, is there some simple math I can use to do this? And how would I implement it in Swing?

Edit: I know how to draw shapes and lines by overriding the drawing method (Graphics g).

+4
source share
2 answers

You can draw a Bezier curve using Java 2D Object Path2D.Double . Just call the curveTo method (float x1, float y1, float x2, float y2, float x3, float y3) and determine the coordinate 3.

  • first bezier breakpoint
  • second bezier breakpoint
  • end point
+9
source

It would be better to read and follow the basic Graphics2D guide, i.e. there are examples here ,

  • some of the examples are deprecated using the wrong paint() method instead of the correct paint() method for the Swing JComponent paintComponent() ,

  • just changing the wrong paint() method to paintComponent() ,

+4
source

Source: https://habr.com/ru/post/1399724/


All Articles