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 ;
}
```
You might also like to view...
If a running thread calls another thread’s________method, the running thread forfeits the GIL and waits for the other thread to die before proceeding.
a) wait. b) join. c) stop. d) None of the above.
A ________ determines whether a field contains an acceptable number of characters.
a. f:validateDoubleRange. b. f:validateLength. c. f:validateLongRange. d. None of the above.
The ________ row in a data source identifies the fields in the remaining rows
A) header B) leader C) range D) record
In the document shown in the accompanying figure, where is the insertion point?
A. Page 2 B. Page 4 C. Page 1 D. Impossible to tell