带颜色的旋转矩形

Rotating Rectangle with Color

我开始在 java 中构建模拟并使用矩形作为平面。但是当我旋转矩形时,它的前景色不会粘在上面。有人可以帮助我吗?

截图:Here

源代码:

 private void drawTransform(Graphics g, double modifier) {

Rectangle rect = new Rectangle(130,350, 350, 15);
    AffineTransform at = new AffineTransform();
    at.rotate(-Math.toRadians(modifier), rect.getX(), rect.getY() + rect.height);

    // Transform the shape and draw it to screen
    Graphics2D g2d = (Graphics2D) g;
    g2d.setColor(Color.red);
    g2d.fillRect(130, 350, 350, 15);
    g2d.draw(at.createTransformedShape(rect));

}

使用fill代替draw:

g2d.fill(at.createTransformedShape(rect));