I need to fill an image created using a ton of QuadCurves, but they don't fill it all the way using the traditional fill method. Any suggestions?

public class MonstercatComponent extends JComponent{
    public void paintComponent(Graphics g){
        Graphics2D g2 = (Graphics2D) g;
        drawGrid(g2);
        g2.setStroke(new BasicStroke(5));
        QuadCurve2D earLeft1 = new QuadCurve2D.Double(145, 155, 137.5, 49, 150, 49);
        g2.draw(earLeft1);
        QuadCurve2D earLeft2 = new QuadCurve2D.Double(150, 49, 156.25, 49, 200, 100);
        g2.draw(earLeft2);
        QuadCurve2D betweenEars = new QuadCurve2D.Double(200, 100, 237.5, 88, 262.5, 87.5);
        g2.draw(betweenEars);
        QuadCurve2D earRight1 = new QuadCurve2D.Double(262.5, 87.5, 287.5, 25, 300, 25);
        g2.draw(earRight1);
        QuadCurve2D earRight2 = new QuadCurve2D.Double(300, 25, 312.5, 25, 337.5, 137.5);
        g2.draw(earRight2);
        CubicCurve2D headPhoneLeft = new CubicCurve2D.Double(145, 155, 75, 175, 100, 250, 150, 250);
        g2.draw(headPhoneLeft);
        CubicCurve2D headPhoneRight = new CubicCurve2D.Double(337.5, 137.5, 387.5, 137.5, 393.75, 188, 362.5, 225);
        g2.draw(headPhoneRight);
        QuadCurve2D headbandTop1 = new QuadCurve2D.Double(109, 177, 150, 75, 225, 50);
        g2.draw(headbandTop1);
        QuadCurve2D headbandTop2 = new QuadCurve2D.Double(225, 50, 300, 50, 372, 150);
        g2.draw(headbandTop2);
        QuadCurve2D headbandBottom1 = new QuadCurve2D.Double(135, 155, 150, 112.5, 212.5, 78);
        g2.draw(headbandBottom1);
        QuadCurve2D headbandBottom2 = new QuadCurve2D.Double(212.5, 78, 306.25, 78, 351, 137.5);
        g2.draw(headbandBottom2);
        QuadCurve2D faceBottomLeft = new QuadCurve2D.Double(150, 250, 162.5, 275, 200, 300);
        g2.draw(faceBottomLeft);
        QuadCurve2D faceBottomRight = new QuadCurve2D.Double(362.5, 225, 363.5, 237.5, 350, 262.5);
        g2.draw(faceBottomRight);
        CubicCurve2D leftArm = new CubicCurve2D.Double(200, 300, 87.5, 300, 87.5, 375, 188.5, 362.5);
        g2.draw(leftArm);
        CubicCurve2D rightArm = new CubicCurve2D.Double(350, 262.5, 425, 237.5, 450, 300, 375, 325);
        g2.draw(rightArm);
        QuadCurve2D leftLegOuter = new QuadCurve2D.Double(188.5, 362.5, 154, 425, 200, 512.5);
        g2.draw(leftLegOuter);
        QuadCurve2D rightLegOuter = new QuadCurve2D.Double(375, 325, 388.5, 356.25, 387.5, 412.5);
        g2.draw(rightLegOuter);
        QuadCurve2D leftFootTop = new QuadCurve2D.Double(200, 512.5, 125, 500, 130, 562.5);
        g2.draw(leftFootTop);
        QuadCurve2D leftFootBottom = new QuadCurve2D.Double(130, 562.5, 175, 575, 262.5, 562.5);
        g2.draw(leftFootBottom);
        QuadCurve2D leftLegInner = new QuadCurve2D.Double(262.5, 562.5, 237.5, 400, 268.75, 363);
        g2.draw(leftLegInner);
        QuadCurve2D rightLegInner = new QuadCurve2D.Double(268.75, 363, 318.75, 362.5, 337.5, 475);
        g2.draw(rightLegInner);
        QuadCurve2D rightFootBottom = new QuadCurve2D.Double(337.5, 475, 400, 480, 455, 470);
        g2.draw(rightFootBottom);
        QuadCurve2D rightFootTop = new QuadCurve2D.Double(455, 470, 450, 400, 387.5, 412.5);
        g2.draw(rightFootTop);

        CubicCurve2D tailInner = new CubicCurve2D.Double(268.75, 363, 287.5, 450,125, 387.5, 62.5, 400);
        g2.draw(tailInner);

        //QuadCurve2D tailInner1 = new QuadCurve2D.Double(268.75, 363, 275, 387.5, 200, 400);
        //g2.draw(tailInner1);
        //QuadCurve2D tailInner2 = new QuadCurve2D.Double(200, 400, 125, 387.5, 62.5, 400);
        //g2.draw(tailInner2);
        QuadCurve2D tailOuter1 = new QuadCurve2D.Double(62.5, 400, 25, 425, 200, 437.5);
        g2.draw(tailOuter1);
        QuadCurve2D tailOuter2 = new QuadCurve2D.Double(200, 437.5, 287.5, 425, 300, 375);
        g2.draw(tailOuter2);

        int[] x = {175, 200, 225, 225, 287, 300, 309, 337, 325, 309, 302, 292, 240, 227, 226, 215};
        int[] y = {225, 210, 237, 200, 187, 212, 187, 187, 262, 262, 230, 268, 275, 250, 277, 281};
        GeneralPath mouthAndTeeth = new GeneralPath();

        mouthAndTeeth.moveTo(x[0], y[0]);

        for (int index = 1; index < x.length; index++) {
            mouthAndTeeth.lineTo(x[index], y[index]);
        };

        mouthAndTeeth.closePath();
        g2.draw(mouthAndTeeth);

        /*
        g2.fill(earLeft1);
        g2.fill(earLeft2);
        g2.fill(earRight1);
        g2.fill(earRight2);
        g2.fill(betweenEars);
        g2.fill(headbandBottom1);
        g2.fill(headbandBottom2);
        g2.fill(headbandTop1);
        g2.fill(headbandTop2);
        g2.fill(headPhoneLeft);
        g2.fill(headPhoneRight);
        g2.fill(faceBottomLeft);
        g2.fill(faceBottomRight);
        g2.fill(leftArm);
        g2.fill(rightArm);
        g2.fill(leftFootBottom);
        g2.fill(leftFootTop);
        g2.fill(rightFootBottom);
        g2.fill(rightFootTop);
        g2.fill(leftLegInner);
        g2.fill(leftLegOuter);
        g2.fill(rightLegInner);
        g2.fill(rightLegOuter);
        //g2.fill(tailInner1);
        //g2.fill(tailInner2);
        g2.fill(tailOuter1);
        g2.fill(tailOuter2);
        */

    }

Above is paintComponent which is where all the code is located.

You could try combining all those arcs into a single shape that will then fill properly. A Path2D.Double may be the best option.

secondary

  • put all graphics objects to the List

  • inside paintComponent loop inside array of Objects

______________________________________________________

important

  • don't to call anything from paintComponent - GeneralPath mouthAndTeeth = new GeneralPath(); those object must be prepared before, storred in array of painting,

  • paintComponent is designated for custom painting, events are repeatly called, is very insensive,

  • not good idea to create an amination this way (remove every code GeneralPath from painting)

  • 1st. code line inside paintComponent should be super.paintComponent (reseting background, previous painting, ....)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.