Create a movie that has two filled rectangles that move by a random amount in x and y (< 5 pixels) each time. Make sure that they don't go outside the picture.
What will be an ideal response?
```
/**
* Method to r e turn a random amount added to i < 5 but
* che c k ing not to exceed the g i v en max
* @param i the cur r ent v a lue
* @param max the max f o r t h i s d i r e c t i o n ( x or y )
* @return i + some random amount < 5
*/
private int getRandomExtra ( int i , int max)
{
int value = i + randNumGen . next Int ( 5 ) ;
i f ( value > max)
value = max ยก 5 ;
return value ;
}
/**
* Method to make a movie t h a t has a two r e c t a n g l e s moving
* around by adding a random amount l e s s than 5 p i x e l s
* @param d i r e c t o r y the d i r e c t o r y to put the movie
* frames
*/
public void makeTwoRectangleRandMovie ( St r ing d i r e c t o r y )
{
int f ramesPerSec = 3 0 ;
Pi c tur e p = nul l ;
Graphics g = nul l ;
FrameSequencer f rameSequencer =
new FrameSequencer ( d i r e c t o r y ) ;
// loop through the f i r s t second
for ( int i = 0 ; i < f ramesPerSec ; i++)
{
// draw a f i l l e d r e c t a n g l e
p = new Pi c tur e ( 6 4 0 , 4 8 0 ) ;
g = p . ge tGraphi c s ( ) ;
g . s e tCo l o r ( Color .RED) ;
g . f i l lRe c t ( getRandomExtra ( i , 6 3 9 ) ,
getRandomExtra ( i , 4 7 9 )
, 5 0 , 5 0 ) ;
g . s e tCo l o r ( Color .BLUE) ;
g . f i l lRe c t ( getRandomExtra ( i +100 ,639) ,
getRandomExtra ( i , 4 7 9 ) ,
5 0 , 5 0 ) ;
// add frame to s e quenc e r
f rameSequencer . addFrame (p ) ;
}
// p lay the movie
f rameSequencer . play ( f ramesPerSec ) ;
}
```
You might also like to view...
When data values belong to a range rather than a set of values, you can create a list of possible values using the enumeration element.
Answer the following statement true (T) or false (F)
Tool tabs are also called ____.
A. contextual tabs B. picture tabs C. tool buttons D. tool contexts
Which JDK command is correct to run a Java application in ByteCode.class?
a. java ByteCode b. java ByteCode.class c. javac ByteCode.java d. javac ByteCode e. JAVAC ByteCode
____ apply a coordinated set of changes to your entire document.
A. Styles B. Sets C. Themes D. Templates