Write a general rotate method that takes the degrees to rotate the current Picture object and returns a new Picture object. Use the AffineTransform.rotate(double radians) method to do this. You will need to use the general Math.toRadians(int degrees) method to translate the degrees to radians.

What will be an ideal response?

```
public Pi c tur e r o t a t e ( int de g r e e s )
{
// s e t up the r o t a t i o n tranform
Af f ineTrans form rotat eTrans form = new Af f ineTrans form ( ) ;
rotat eTrans form . r o t a t e (Math . toRadians ( de g r e e s ) ) ;
Rectangle2D r e c t =
getTrans formEnclos ingRect ( rotat eTrans form ) ;
// c r e a t e a new p i c t u r e o b j e c t b i g enough to hold the r e s u l t no
// mat ter what the r o t a t i o n i s
Pi c tur e r e s u l t = new Pi c tur e ( ( int ) (Math . c e i l ( r e c t . getWidth ( ) ) ) ,
( int ) (Math . c e i l ( r e c t . ge tHe ight ( ) ) ) ) ;
// g e t the g r a p h i c s 2d o b j e c t from the r e s u l t
Graphics g r aphi c s = r e s u l t . ge tGraphi c s ( ) ;
Graphics2D g2 = (Graphics2D) g r aphi c s ;
// save the cur r ent t rans format ion and s e t¡up to c ent e r the
// r o t a t e d image
Af f ineTrans form savedTrans = g2 . getTransform ( ) ;
Af f ineTrans form c ent e rTrans = new Af f ineTrans form ( ) ;
c ent e rTrans . t r a n s l a t e (0 ¡ r e c t . getX ( ) , 0 ¡ r e c t . getY ( ) ) ;
g2 . setTrans form ( c ent e rTrans ) ;
// draw the cur r ent image onto the r e s u l t image r o t a t e d
g2 . drawImage ( this . getImage ( ) , rotateTrans form , nul l ) ;
// r e s e t g2 t rans format ion to the saved one
g2 . setTrans form ( savedTrans ) ;
return r e s u l t ;
}
```

Computer Science & Information Technology

You might also like to view...

Using a(n) ________ is a violation of Facebook policies, and users can have their accounts suspended if someone reports it

Fill in the blank(s) with correct word

Computer Science & Information Technology

Compare, Contrast, and View Side By Side are three ways that Word offers to allow a user to view revisions in two documents to determine which changes to accept or reject

Indicate whether the statement is true or false

Computer Science & Information Technology