The ControlPanel class is the same for all algorithms.  It is a frame with start, suspend, step, exit, and restart buttons.  It also has a scroll bar and text field.  It controls the function of the algorithm through calls to MainApplet.  It can start and stop the algorithm.  It can step through the algorithm and it can change the algorithm's speed.


Method Index

public ControlPanel(MainApplet ma)


  1. ma is an instance of MainApplet.  MainApplet instantiates ControlPanel and passes a reference to itself to ControlPanel

Calls buildUI()

public int getSpeed()

Returns speed; MainApplet retrieves the speed from ControlPanel and MainApplet uses this to set the initial speed of the algorithm.

public void exit()

Disposes of the control panel frame.  This method is called by MainApplet when the algorithm is exited.

public void start()

Calls startAlg() on the MainApplet object, writes the current speed to the speedField, and sets the modeField of MainApplet to running.

public void suspend()

Calls suspendAlg() on the MainApplet object and sets the modeField of MainApplet to suspended.

private void buildUI()

Builds the user interface and makes instance of ControlPanel a listener of the buttons, scrollbar and text field.

public void actionPerformed(ActionEvent e)


  1. e is an ActionEvent.

The type of ActionEvent is determined.

  1. Start: this button starts the algorithm by calling startAlg() in MainApplet
  2. Suspend: this button suspends the algorithm by calling suspendAlg() in MainApplet
  3. Step: this button steps through one step point in the algorithm by calling stepAlg() in MainApplet
  4. Exit: this button exits the algorithm and closes the ControlPanel frame and animation frame.
  5. Restart: this button performs an exit and automatically starts the algorithm anew.  It is like pressing the exit button on the control panel and then immediately pressing Start Animation on the main applet.  A call to startAnimation() is made, so if any changes have been made to the main applet, the algorithm will reflect those changes when it restarts.
  6. Entry in the TextField: if the new entry is between 1 and 20 the speed is changed with a call to setSpeed() in MainApplet.  The scroll bar is also adjusted properly.

public void adjustmentValueChanged(AdjustmentEvent e)


  1. e is an AdjustmentEvent

This is used to detect when the scroll bar is adjusted.  The scroll bar is used to set the algorithm speed with a call to setSpeed() in MainApplet.  The TextField is also modified to match the scroll bar.

public void windowClosing(WindowEvent e)


  1. e is a WindowEvent.

e occurs when the close (X) button on the control panel frame is pressed.  The control panel frame is disposed and a the algorithm is exited.

Ted Jenks