Goals

Submission
  • You do not need to submit the warmup exercise.

  • Part 0

  • Create a public_html directory if you don't already have one. This will enable you to access your applets on the Web. Use the following sequence of commands.
    cd                             # change to your root directory
    mkdir public_html              # create the directory
    chmod 755 public_html          # adjust read permissions
    

  • Copy the following files from /u/cs126/files/bounce/ into your public_html directory, and make the appropriate files world readable.
    MovingBall.html   MovingBall.java   sun.gif   splat.au
    earth.gif         gong.au
    
    You can do this with the following commands:
    cd ~/public_html               # move to appropriate directory
    cp /u/cs126/files/bounce/* .   # copy files
    

  • Compile with the command:
    javac MovingBall.java
    
    This will create the following two files:
    Ball.class   MovingBall.class
    

  • To execute the applet, use the command:
    appletviewer MovingBall.html
    
    If everything goes properly, you should see a picture of the sun moving off the screen. If not, make sure you did the previous steps correctly. You will not be able to continue until you get this working.

  • To view under a Web browser, you need to set the appropriate files to be world readable. To do this, use the command:
    chmod 644 *.html *.gif *.au *.class
    
    Next, load the page www.cs.princeton.edu/~login/MovingBall.html in your Web browser. After recompiling the applet, you may need to enter Shift-Reload instead of Reload to properly reload your applet.

  • Part 1    (bounce off window)

  • Modify the file MovingBall.java so that the ball stays withing the window. Keep the x and y components between -1/2 and 1/2. Note that method move determines the size of the current window and rescales the x and y components to fill up the window.

  • Part 2    (sound)

  • Add a sound effect when the ball hits the window boundary. The following method call will play the .au soundfile assoicated with the ball.
    AudioClip.play();
    

  • Part 3    (add a second ball)

  • Add a second ball with a different initial position and velocity. You can use the .gif file earth.gif and the sound file gong.au.

  • Feel free to add more balls. You can find additional images and sound files from the Web.

  • Enrichment Links

  • Check the Java section of the Frequently Asked Questions page for more info and relevant links.

  • Check out Oxford Sound Archive or Wave Central for more sound files.



  • Kevin Wayne