aspose file tools*
The moose likes Beginning Java and the fly likes Rotating a Graphic Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Rotating a Graphic" Watch "Rotating a Graphic" New topic
Author

Rotating a Graphic

Steven Joost
Greenhorn

Joined: Sep 29, 2012
Posts: 28
Hello guys, I want to make a Graphic rotating, but don't know how.
I'm using GeneralPaths, and already wrote this:


The result is a blue square, and I only need a formula for rotating the corners of p.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39436
    
  28
Do you mean that you rotate it the way a sheet of paper would rotate while lying on the table?
I suggest you try affine transforms on the Graphics object. Somebody else asked a similar question last week, so you could adapt what I said here, by using the rotate() method. It is worth finding out whether you rotate in degrees or radians, and whether it is clockwise or anticlockwise.
Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 2318
    
  49
Also you shouldn't put a sleep in the paintComponent method or the GUI will just hang. If you want to repaint at a regular interval use a Timer to call repaint every n milliseconds.
Kemal Sokolovic
Bartender

Joined: Jun 19, 2010
Posts: 825
    
    5

You should cast your Graphics to Graphics2D at the beginning of your method and work with it.

To apply rotation (or even some other transformation) on your coordinates, you should check the AffineTransform API for more information. For your requirement:

In case you want to apply transformation just temporary, you can get old transformation that will be set back after the one you're doing:


The quieter you are, the more you are able to hear.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Rotating a Graphic