LAB 42 – Creating and Modifying Movies
Lab Exercises
Topics
Using BlueJ to start a new application
1) Starting BlueJ or DrJava - double-click icon.
2) Add bookClasses to libraries through preferences
3) Creating a new project - select New Project from the Project menu and save the project as Lab42.
4) Click on New Class and type Movie as the class name and select Class as the class type
5) Right-click on the Movie class and select Open Editor
6) Replace the code generated by BlueJ with the following; update the comments.
public class movie
{
public static void main(String[] args)
{
MovieMaker movieMaker = new MovieMaker();
String dir = "c:/temp/movies/rectangle/";
movieMaker.makeRectangleMovie(dir);
}
}
7) Click on New Class and type MovieMaker as the class name and select Class as the class type
8) Right-click on the MovieMaker class and select Open Editor
9) Replace the code generated by BlueJ with the following; update the comments
public
class MovieMaker
{
public void makeRectangleMovie(String directory)
{
int framesPerSec = 30;
Picture p = null;
Graphics g = null;
FrameSequencer frameSequencer = new FrameSequencer(directory);
frameSequencer.setShown(true);
// loop through the first second
for (int i = 0; i < framesPerSec; i++)
{
// draw a filled rectangle
p = new Picture(640,480);
g = p.getGraphics();
g.setColor(Color.RED);
g.fillRect(i * 10, i * 5, 50,50);
// add frame to sequencer
frameSequencer.addFrame(p);
}
// play the movie
frameSequencer.play(framesPerSec);
}
}
10) To run the program, right-click on the Movie class and select and select void main (String[] arguments)
11) This should pop-up a terminal window with results
12) Modify the MovieMaker class so that there are at least two objects (filled rectanges, ovals, text) moving a random x and y amount (<5 pixels) each step of the animation. Make sure that the objects do not leave the screen.
13) Compile and run the modified program.
QUESTIONS: Submit Movie.java and MovieMaker.java to the DropBox in WebCT.