cis20.1-fall2007-sklar, assignment II, part 1

INFORMATION


INSTRUCTIONS

  1. For this part of the assignment, you will create several HTML and Java files.
  2. When you are completely finished with all the steps in BOTH PARTS of the assignment, zip all your files together and email the zip file to me as an attachment.
  3. The subject line of your email should say: cis20.1 hwII
  4. My email address is: sklar@sci.brooklyn.cuny.edu.
THE ASSIGNMENT--BOTH PARTS--ARE DUE ON OCTOBER 29, 2007.

BE SURE TO ASK IN THE LAB IF YOU NEED HELP WITH ANY STEPS!!!!


Step 0.

Run the bounce example: http://www.sci.brooklyn.cuny.edu/~sklar/cis20.1/examples/bounce.html
Download the source code from the example. You need to download four files: Bounce.java, Stage.java, Ball.java and bounce.html.

Compile the 3 Java files and then try running them on your computer by calling up bounce.html in your browser.


Step 1.
(2 points)

Create Bounce1.java which extends Bounce.java and add a stop button to the user interface. When this button is clicked, all the balls should stop running--- i.e., the applet should stop. (Note that when you click on add balls, faster or slower, the balls should resume bouncing.)

Copy bounce.html to bounce1.html and make it start up Bounce1.class.


Step 2.
(2 points)

Create Bounce2.java by extending Bounce1.java and changing it so that the background of the Canvas is not black but is an Image. Note that you will also need to create Stage2.java, by extending Stage.java in order to use the image. You will also need to edit Stage.java, making some of the fields public instead of private so you can use them in Stage2.java.

Here's an image to use for your background. It is 400 pixels wide by 300 pixels high: http://www.sci.brooklyn.cuny.edu/~sklar/cis20.1/examples/102-0252_IMG-small.JPG (You can also use your own image if you want.)

Copy bounce1.html to bounce2.html and make it start up Bounce2.class.

Test, as above.


Step 3.
(2 points)

Create Bounce3.java by extending Bounce2.

Instead of using buttons, make two pulldown menus. One menu should contain things related to the balls: add, faster and slower. The second menu should contain things related to the applet: start, stop and exit. Attach behavior to start and exit. Note that start only has meaning when balls have already been added and if the display has been stopped. When exit is selected, the applet should invoke the following URL: http://www.sci.brooklyn.cuny.edu/~sklar/cis20.1/examples/bye.html

Here is a snippet of code for how to do this:

try {
  URL url = new URL( "http://www.sci.brooklyn.cuny.edu/~sklar/cis20.1/examples/bye.html" );
  getAppletContext().showDocument( url );
}
catch( MalformedURLException murlx ) {
}
catch( IOException iox ) {
}

Copy bounce2.html to bounce3.html and make it start up Bounce3.class.

Test, as above.