<< Chapter < Page Chapter >> Page >
  • Crops the snow scene to remove the Alice runtime panel.
  • Crops the three views of the skater to remove the Alice runtime panel along with excess blank green background.
  • Scales two of the views of the skater to smaller sizes.
  • Does green-screen processing to place the three views of the skater at different locations in the snow scene.
  • Uses position along with size to create an optical illusion of a 3D scene of three ice skaters and a penguin standing at different locations ona frozen lake (see Figure 5 ) .

Programming skills required

In order to write this program, the student must be able to, as a minimum, write a green-screen processing method.

Discussion and sample code

Will discuss in fragments

I will discuss this program in fragments. A complete listing of the program is provided in Listing 6 near the end of the lesson.

The driver class named Prob03

The driver class containing the main method is shown in Listing 1 .

Listing 1 . The driver class named Prob03.
import java.awt.Color;public class Prob03{ public static void main(String[]args){ Prob03Runner obj = new Prob03Runner();obj.run(); }//end main}//end class Prob03

The main method in Listing 1 instantiates a new object of the class named Prob03Runner and calls the method named run that belongs to that object.

When the run method returns, the program terminates.

Beginning of the class named Prob03Runner

The beginning of the class named Prob03Runner , and its constructor, is shown in Listing 2 .

Listing 2 . Beginning of the class named Prob03Runner.
class Prob03Runner{ public Prob03Runner(){//constructorSystem.out.println("Display your name here."); }//end constructor

The constructor simply displays the student's name on the command line screen producing the first line of text shown in Figure 6 .

Beginning of the run method

The beginning of the run method that is called in Listing 1 is shown in Listing 3 .

Listing 3 . Beginning of the run method.
public void run(){ //A view facing the front of the skater.Picture front = new Picture("Prob03a.bmp"); front.explore();front = crop(front,123,59,110,256); //A view showing the right side of the skater.Picture right = new Picture("Prob03b.bmp"); right.explore();right = crop(right,123,59,110,256); //A view showing the left side of the skater.Picture left = new Picture("Prob03c.bmp"); left.explore();left = crop(left,123,59,110,256); //This will be the background for the new picture.Picture snowScene = new Picture("Prob03d.jpg"); snowScene.explore();snowScene = crop(snowScene,6,59,344,256);

The code in Listing 3 instantiates, displays, and crops the four input images.

All four images must be cropped to remove the Alice runtime window. In addition, the three skater images are also cropped to remove excess blank greenbackground material.

Image formats: bmp versus jpg

Note that the three views of the skater are extracted from bmp image files instead of jpg image files. This is necessary in order to preserve the pure green background color. Storing the images as jpg files would corrupt the background color in the low order bits making it moredifficult to achieve the green-screen processing required by this program.

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Object-oriented programming (oop) with java. OpenStax CNX. Jun 29, 2016 Download for free at https://legacy.cnx.org/content/col11441/1.201
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Object-oriented programming (oop) with java' conversation and receive update notifications?

Ask