Search code examples
javaswinggraphics2dpaintcomponent

How can I draw a curved line segment using QuadCurve2D.Double?


Here is the line of code where I declare the curve:

QuadCurve2D.Double curve = new QuadCurve2D.Double(50,100,100,170,150,100);

Now what code can I use to draw this curve? I tried something like:

g.draw(curve);

but obviously that didn't work. Any suggestions?


Solution

  • I've made a minimum test case of what I think your describing here. This program works but I can't really help you unless I can see the code you are working with.

    import java.awt.geom.*;
    import java.awt.*;
    import javax.swing.*;
    
    public class CurveDraw extends JFrame {
            public static void main(String[] args) {
                    CurveDraw frame = new CurveDraw();
                    frame.setVisible(true);
            }
            public CurveDraw() {
                    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                    setSize(400,400);
            }
            public void paint(Graphics g) {
                    QuadCurve2D.Double curve = new QuadCurve2D.Double(50,100,100,170,150,100);
                    ((Graphics2D)g).draw(curve);
            }
    }