旋转矩形颜色

时间:2016-02-21 17:48:22

标签: java graphics2d

我开始在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));

}

1 个答案:

答案 0 :(得分:0)

使用fill代替draw

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