CSci 157 - Lab 10

The purpose of this lab is to practice using the Java Swing classes for Graphical User Interfaces.

Complete the three classes described below, using the GUI notes given out in class (also found here) and example code provided. You'll need the FallingBall class as starter code for each project.

To start, the Driver will be the one whose last name comes first, alphabetically. Switch when you get to Problem 3.
  1. SliderBallController - You're going to re-create the SliderBallController program demonstrated in lecture.  To do this:

  2. Add a label for the JSlider in SliderBallController as described in the GUI notes.  You'll need to do the following:
  4. SwitchUse the code from Section 11.7.2 to create a KeyBallController class.  This version controls the speed of the ball using the up-arrow and down-arrow keys. The notes describe how keystrokes are dealt with on pages 27 and 28, but not in detail.  Since this one just use keystrokes, no Swing components are needed, so the ContentPane object is not strictly necessary; canvas can be used instead.

    To recognize keystrokes, the class implements KeyListener.  This interface defines three methods, but we only need one, keyPressed.  Because the interface requires that all three methods must be provided, two have empty bodies.  This is an acceptable and often-used Java idiom.

    Notice that you can do strange things to falling balls, stopping them or making them fall "upwards."  It can be fun to play with the ≈ physics of alternate universes, but in our universe things fall without stopping.  Modify the program to keep the speed from going beyond FAST_SPEED when pressing up-arrow, or lower than SLOW_SPEED when pressing down-arrow.  You'll want to make sure you have those constants defined in your class.
  5. Add multiple falling balls to ButtonBallController using arrays!