Skip to content
Advertisement

Drawing rectangles at an angle

What is a method in Java that draws a rectangle given the following:

  • The coordinates of the center of the square
  • The angle of the rectangle from vertical, in degrees

Advertisement

Answer

To draw a rectangle in the way you suggest you need to use the class AffineTransform. The class can be used to transform a shape in all manner of ways. To perform a rotation use:

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement