[英]Rotating Rectangle with Color
I am starting to build a simulation in java and using a rectangle as a plane. 我开始在Java中建立仿真,并使用矩形作为平面。 But as I rotate the rectangle its foreground color won't stick to it. 但是当我旋转矩形时,它的前景色不会粘在它上面。 Can someone help me? 有人能帮我吗?
Source Code: 源代码:
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));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.