先请大家运行代码 我想填充当前图形,可一旦g.fill后它却把弧闭合了,和我需要的不同填充的不同
请问有什么办法可以解决吗?
import java.awt.*;
import java.awt.geom.*;
import javax.swing.*;public class TestArcPath extends JFrame {
   public TestArcPath() {
      Container c = getContentPane();
      PaintSwing ps = new PaintSwing();
      c.add(ps);
      setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      setSize(400, 400);
      setVisible(true);
   }
   
   public class PaintSwing extends JPanel {
      public void paint(Graphics g) {
         super.paint(g);
         Graphics2D g2 = ((Graphics2D) g);
         double height = 20;
         Arc2D arc = new Arc2D.Double(200, 200, 200, 100, 101.85, 74, Arc2D.PIE);
         GeneralPath gpath = new GeneralPath();
         gpath.append(new Line2D.Double(arc.getEndPoint().getX(),
                      arc.getEndPoint().getY(), arc.getEndPoint().getX(),
                      arc.getEndPoint().getY() + height), false);
         gpath.append(new Arc2D.Double(arc.getX(), arc.getY() + height,
                      arc.getWidth(), arc.getHeight(), arc.getAngleStart(),
                      arc.getAngleExtent(), Arc2D.OPEN), false);
         gpath.append(new Line2D.Double(arc.getStartPoint().getX(),
                      arc.getStartPoint().getY()  + height,
                      arc.getStartPoint().getX(), arc.getStartPoint().getY()),
                      false);
         gpath.append(new Arc2D.Double(arc.getFrame(), arc.getAngleStart(),
                      arc.getAngleExtent(), Arc2D.OPEN), false);
         g2.draw(gpath);
//         g2.fill(gpath);//         gpath.moveTo((float) arc.getStartPoint().getX(),
//                      (float) arc.getStartPoint().getY());
//         gpath.append(new Arc2D.Double(arc.getFrame(), arc.getAngleStart(),
//                      arc.getAngleExtent(), Arc2D.OPEN), false);
//         gpath.moveTo((float) arc.getEndPoint().getX(),
//                      (float) arc.getEndPoint().getY());
//         gpath.lineTo((float) arc.getEndPoint().getX(),
//                      (float) (arc.getEndPoint().getY() + height));
//         gpath.append(new Arc2D.Double(arc.getX(), arc.getY() + height,
//                      arc.getWidth(), arc.getHeight(), arc.getAngleStart(),
//                      arc.getAngleExtent(), Arc2D.OPEN), false);
//         gpath.moveTo((float) arc.getStartPoint().getX(),
//                      (float) (arc.getStartPoint().getY() + height));
//         gpath.lineTo((float) arc.getStartPoint().getX(),
//                      (float) arc.getStartPoint().getY());
//         g2.fill(gpath);
      }
   }
   
   public static void main(String[] args) {
      new TestArcPath();
   }
}