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.
public ControlPanel(MainApplet ma)
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)
The type of ActionEvent is determined.
public void adjustmentValueChanged(AdjustmentEvent e)
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)
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.