Speed Control

The files SpeedControl.java and SpeedControlPanel.java contain an applet (and its associated panel) with a circle that moves on the panel and rebounds from the edges. (NOTE: the program is derived from Listing 8.19 and 8.20 in the text. You may have used the Circle class in Circle.java in an earlier lab on animation.) Save the program to your directory and run it in the appletviewer (you may use the file Speed.html) to see how it works.

In this lab exercise you will add to the panel a slider that controls the speed of the animation. Study the code in ViewSliderPanel.java (Listing 9.17 in the text) to help understand the steps below.

  1. Set up a JSlider object. You need to

  2. Set up the change listener for the slider. A skeleton of a class named SlideListener is already in SpeedControlPanel.java. You need to

  3. Create a label ("Timer Delay") for the slider and align it to the left.

  4. Create a JPanel object and add the label and slider to it then add your panel to the SOUTH of the main panel (note that it has already been set up to use a border layout).

  5. Compile and run the applet. Make sure the speed is changing when the slider is moved. (NOTE: Larger delay means slower!)

  6. You should have noticed one problem with the applet. The ball (circle) goes down behind the panel the slider is on. To fix this problem do the following: