Ball World



Second Laboratory: Interfaces, Classes and Objects

Ball world is designed to give students their first experience writing a class and implementing an interface. The result of their efforts is easily visible in a graphical context. In this lab students write and compile a class that implements the Ball interface. Once this class is compiled it can be loaded into the program. For Each loaded Ball class the program will create a button. clicking the button creates a new instance of the ball in the ballworld, which will regular query the location and radius of the ball and redraw it accordingly. The ball world also sends mouse clicks to the ball containing the clicked point (if any), and sends keys typed to the currently selected ball.

Running the Program

There are many ways to run the code in class. You should choose the one that your students are ready for. They are presented in an order that represents an increasing usage of the command line utilities and options.

1.)a) Click here
   b) File > Expand Classpath > (choose jar/dir of package of student code.)   
   c) File > Load Ball > (enter fully qualified Class name for student code)

      (requires Java WebStart). If you want to put a link on your course 
      web site, you may use a link like this (subject to our terms of use 
      like all materials on the site): 

      <a href="http://www.cs101.org/psets/ballworld/demo/ballworld.jnlp">Click Here</a>

2. a) java -jar ballworld.jar
   b) File > Expand Classpath > (choose jar/dir of package of student code.)   
   c) File > Load Ball > (enter fully qualified Class name for student code)

3. a) java -cp ballworld.jar ballworld.Main
   b) File > Expand Classpath > (choose jar/dir of package of student code.)
   c) File > Load Ball > (enter fully qualified Class name for student code)

4. a) java -cp "ballworld.jar:/path/to/student/code" ballworld.Main
   b) File > Load Ball > (enter fully qualified Class name for student code)

5. a) java -cp "ballworld.jar:/path/to/student/code" ballworld.Main stupkg.StudentBall [stupkg.StudentBall2]

6. a) jar -xvf ballworld.jar
   b) java ballworld.Main
   c) File > Expand Classpath > (choose jar/dir of package of student code.)
   d) File > Load Ball > (enter fully qualified Class name for student code)

7 thru 9 same permutations on the unpacked executable jar.

10 - 13 again but start with the source jar, add compilation step(s).

(Line 6b assumes that you have the current directory on your default class path)

Usage Notes

Screen Shots

This image show the ball world with two Throbber balls (which change radius in and out) and an exploder ball which has explodded into a couple dozen balls. The upper left throbber is the currently selected ball so it is rendered in red.

screen shot of the ballworld program

This image is a second screen shot from the same run of the program. A new type of ball has been loaded (Faller) and five of them have been added to the Ball World. The exploder shown is not the same exploder, since exploders disintigrate rather quickly. The last Faller added is the currently selected ball.

second screen shot of the ballworld program

This page is a part of Lynn Andrea Stein's Rethinking CS101 project, part of the Computers and Cognition Group at the Franklin W. Olin College of Engineering.
This material is based upon work supported by the National Science Foundation under Grant No. EIA-0196404. Any opinions, findings, and conclusions or recommendations expressed in this material are those of the author(s) and do not necessarily reflect the views of the National Science Foundation
Valid HTML 4.01!
Valid CSS!
cs101-webmaster@olin.edu
Last modified: Monday, December 5 2005 at 5:19 AM EST