Create a class CartoonPanel and create a constructor that takes an array of Picture objects and displays them from left to right like a cartoon in a newspa- per. You can use the scale method to scale the pictures to ¯t. You can create a new picture to use to display the cartoon on.

What will be an ideal response?


```
/**
* Clas s t h a t shows an ar ray of p i c t u r e s and
* shows them from l e f t to r i g h t in a p i c t u r e
* @author Barb Er icson er icson@cc . gat e ch . edu
*/
public clas s CartoonPanel
{
/** f i e l d t h a t h o l d s the ar ray of p i c t u r e s */
private Pi c tur e [ ] pi c tur eAr ray ;
/** f i e l d t h a t i s the width of the car toon pane l */
private int width = 640;
/** f i e l d t h a t i s the amount to s c a l e each p i c t u r e in x */
private double xScal e ;
/** f i e l d t h a t i s the amount to s c a l e each p i c t u r e in y */
private double yScal e ;
/** f i e l d t h a t i s the amount of space to l e a v e between p i c t u r e s */
private int gap = 5 ;
/**
* Cons t ruc tor t h a t t a k e s an ar ray of p i c t u r e s
* @param pi c tAr ray the ar ray of p i c t u r e s
*/
public CartoonPanel ( Pi c tur e [ ] pi c tAr ray )
f
this . pi c tur eAr ray = pi c tAr ray ;
}
/**
* Method to c a l c u l a t e the h e i g h t and x and y s c a l e
* amounts
*/
public int ca l cula t eHe ightAndSe tSca l e ( )
{
int totalWidth = 0 ;
int maxHeight = 0 ;
int maxWidth = 0 ;
// loop through a l l p i c t u r e s
for ( Pi c tur e cur rPi c t : pi c tur eAr ray )
{
totalWidth = totalWidth + cur rPi c t . getWidth ( ) ;
i f ( cur rPi c t . ge tHe ight ( ) > maxHeight )
maxHeight = cur rPi c t . ge tHe ight ( ) ;
i f ( cur rPi c t . getWidth ( ) > maxWidth)
maxWidth = cur rPi c t . getWidth ( ) ;
}
// add gap to t o t a l width
totalWidth = totalWidth + ( pi c tur eAr ray . l eng th ¡ 1) * gap ;
// c a l c u l a t e the s c a l i n g f a c t o r s and h e i g h t
xScal e = ( ( double ) width ) / totalWidth ;
yScal e = xScal e ;
int he i ght = ( int ) ( yScal e * maxHeight ) ;
return he i ght ;
}
/**
* method to show the car toon pane l
*/
public void show ( )
{
// c a l c u l a t e the h e i g h t and x and y s c a l e amounts
int he i ght = c al cul at eHe i ghtAndSe tSc al e ( ) ;
// c r e a t e a new p i c t u r e of the c o r r e c t width and h e i g h t
Pi c tur e p = new Pi c tur e (width , he i ght ) ;
// s t a r t of cur r p i c t u r e in car toon pane l
int currX = 0 ;
// loop through the p i c t u r e s in the ar ray
for ( Pi c tur e cur rPi c t : pi c tur eAr ray )
{
cur rPi c t = cur rPi c t . s c a l e ( xScale , yScal e ) ;
p . copy ( cur rPi c t , currX , 0 ) ;
currX = currX + cur rPi c t . getWidth ( ) + gap ;
}
// show the p i c t u r e
p . show ( ) ;
}
/**
* Method to t e s t the car toon pane l c l a s s
*/
public s tat ic void main ( St r ing [ ] args )
{
Pi c tur e p = new Pi c tur e ( Fi l eChoos e r . getMediaPath ( " church . jpg " ) ) ;
Pi c tur e p1 = new Pi c tur e ( Fi l eChoos e r . getMediaPath ( "beach . jpg " ) ) ;
Pi c tur e p2 = new Pi c tur e ( Fi l eChoos e r . getMediaPath ( " e i f f e l . jpg " ) ) ;
Pi c tur e [ ] pi c tAr ray = fp , p1 , p2 g ;
CartoonPanel panel = new CartoonPanel ( pi c tAr ray ) ;
pane l . show ( ) ;
}
}
```

Computer Science & Information Technology

You might also like to view...

Referring to the accompanying figure, which port is pointed to by callout B?

A. VGA B. DVI C. HDMI D. USB

Computer Science & Information Technology

Project 2010 automatically appends the ____ filename extension to identify the file as a Microsoft Project 2010 file.

A. .mpp B. .pro C. .prj D. .mpj

Computer Science & Information Technology

Windows 8.1 Update is the latest version of the Windows ________

Fill in the blank(s) with correct word

Computer Science & Information Technology

CSMA/CD is implemented at the data link layer on wireless networks.

Answer the following statement true (T) or false (F)

Computer Science & Information Technology