Spring 2002, CSE 428: Assignment 5


Distributed: Mar 26.
Due: April 11 in class.
Total maximum score: 200 points.

The purpose of this assignment is to provide experience with Event Programming in Java


This applet visulizes a bouncing ball on the screen. Click here for a demo.

The assignment consists in modifying the above applet so to make it possible to add new balls. More specifically, the applet should visualize a menu choice in which the user can choose the color of the new ball to be added, and then allow the user to set the initial position and the direction and speed of the ball with two consecutive clicks of the mouse (the first click for the position, the second for the direction and and speed. The speed should depend on the distance between the two clicks). Furthermore, the applet should have a "clear button" and a text field for the essential messages to the user (to tell the user the the coordinates of the mouse click, and ask the user to click in another point). Here is a demo of how the solution should look like.

Bonus

If you add to the solution a New Ball button and a Mouse Motion Handler so to visualize the movement of the mouse when a new ball is added, like it is done here, you will receive 100 bonus extra points on the assignments. Please note that in order to receive this bonus your applet should behave exactly like the above one. If you decide to go for the bonus, please add the word "BONUS" in the subject of your email when you submit the solution, and in the hard copy of your solution.

Please note the following:

  1. Please make sure that your applet can be compiled with the Unix javac and executed with the Unix java. Solutions which cannot be compiled or executed will receive, at most, 40 points.
  2. Please call the main class of your program BouncingBalls and save it in a file named BouncingBalls.java. Make sure that the program can be compiled with the following command:
           javac BouncingBalls.java
           
  3. Its your responsibility to write a sound, reliable program, so please test your code thoroughly before submitting it.

Testing the solution

To test your solution, save in your www directory the html source of this link. Put in the same directory also the file BouncingBalls.java and then compile it. Make sure that the access rights are set correctly: 755 for the class files and 644 for the html file. To do this the command is chmod. For instance, chmod 755 BouncingBalls.class. Note that there are several class files which are subclasses of BouncingBalls, so it's best to do chmod 755 BouncingBalls*.class. Finally, visit BouncingBalls.html as a web address from Netscape.

If you don't have a www directory, you can create it with the command mkdir www. Note that also the rights of www have to be set to 755.

Format of the solution

Please give an hard copy of the source program to the instructor by the due date. Furthermore, you should also email your sources to cg428@cse.psu.edu by the due date, so to allow us to check that they run correctly. Please send the file BouncingBalls.java as attachment, not by "cut-and-paste". Please write in the subject of the email your section, your name, and your student id.