Reputation: 13
public void paint(Graphics g) {
Rectangle rectangle = new Rectangle(100,100,100,100);
Graphics2D g2d = (Graphics2D) g;
AffineTransform transform = new AffineTransform();
transform.rotate(
Math.toRadians(45), rectangle.getX() + rectangle.width/2,
rectangle.getY() + rectangle.height/2
);
g2d.draw(transform);
}
I am trying to rotate a rectangle around a center, but its not working. I am getting this error:
The method draw(Shape) in the type Graphics2D is not applicable for the arguments (AffineTransform)
Upvotes: 1
Views: 108
Reputation: 3138
The error indicates that you cannot call this method with transform.
You should try to call setTransform
first and then draw
the rectangle.
public void paint(Graphics g) {
Rectangle rectangle = new Rectangle(100,100,100,100);
Graphics2D g2d = (Graphics2D) g;
AffineTransform transform = new AffineTransform();
transform.rotate(
Math.toRadians(45), rectangle.getX() + rectangle.width/2,
rectangle.getY() + rectangle.height/2
);
g2d.setTransform(transform);
g2d.draw(rectangle);
}
Upvotes: 2