填充颜​​色自定义形状 Java

Fill Color Custom Shape Java

我想在自定义形状中填充颜色

这是我的梯形代码

梯形Class

public class Trapezium implements Shape {
private GeneralPath trapezium = new GeneralPath();

public Trapezium (Point2D A, double height, double width)
{

    double Ax = A.getX();
    double Ay = A.getY();

    double Bx = Ax + (width/6);
    double By = Ay;

    double Cx = Bx + (width/3);
    double Cy = By + height;

    double Dx = Cx - width;
    double Dy = Cy;

    double Ex = Dx + (width/3);
    double Ey = Dy - height;


    trapezium.moveTo(Ax, Ay);
    trapezium.lineTo(Bx, By);
    trapezium.lineTo(Cx, Cy);
    trapezium.lineTo(Dx, Dy);
    trapezium.lineTo(Ex, Ey);
    trapezium.closePath();

}

@Override
public java.awt.Rectangle getBounds() {
    return trapezium.getBounds();
}

@Override
public Rectangle2D getBounds2D() {
    return trapezium.getBounds2D();
}

@Override
public boolean contains(double x, double y) {
    return trapezium.contains(x, y);
}

@Override
public boolean contains(Point2D p) {
    return trapezium.contains(p);
}

@Override
public boolean intersects(double x, double y, double w, double h) {
    return trapezium.intersects(x, y, w, h);
}

@Override
public boolean intersects(Rectangle2D r) {
        return trapezium.intersects(r);
}

@Override
public boolean contains(double x, double y, double w, double h) {
    return trapezium.contains(x, y,w ,h);
}

@Override
public boolean contains(Rectangle2D r) {
    return trapezium.contains(r);
}

@Override
public PathIterator getPathIterator(AffineTransform at) {
    return trapezium.getPathIterator(at);
}

@Override
public PathIterator getPathIterator(AffineTransform at, double flatness) {
    return trapezium.getPathIterator(at, flatness);
}
}

这是我调用梯形时的代码class

绘图面板Class

else if(type.get(a).equals("Trapezium"))
{
    int[]coordinates=allShapes.get(a);
    Point2D b= new Point2D.Double(coordinates[0], coordinates[1]);

    Trapezium trapezium = new Trapezium(b,coordinates[3], coordinates[2]);
    g2.setStroke(new BasicStroke(coordinates[4]));
    g2.setPaint(dragColor);
    g2.draw(trapezium);
}

setPaint 只为形状的笔触着色,如何为形状的内部着色?

Image of my current code when executed

编辑

我有2个JColorChooser,1个是形状的描边,2个是形状内部的颜色

如果我使用

g2.setPaint(颜色2) g2.fill(梯形)

如何让 color1 改变我笔触的颜色?

你只需填充形状^_^

Trapezium trapezium = new Trapezium(b,coordinates[3], coordinates[2]);
g2.setStroke(new BasicStroke(coordinates[4]));
g2.setPaint(dragColor);
g2.fill(trapezium); //HERE!!!!