* Stop the applet. Kill any sorting algorithm that
* is still sorting.
*/
public synchronized void stop() {
if (algorithm != null){
try {
algorithm.stop();
} catch (IllegalThreadStateException e) {
// ignore this exception
}
kicker = null;
}
}
/**
* For a Thread to actually do the sorting. This routine makes
* sure we do not simultaneously start several sorts if the user
* repeatedly clicks on the sort item. It needs to be
* synchronoized with the stop() method because they both
* manipulate the common kicker variable.
*/
private synchronized void startSort() {
if (kicker == null || !kicker.isAlive()) {
kicker = new Thread(this);
kicker.start();
}
}
//1.1 event handling
public void mouseClicked(MouseEvent e)
{}
public void mousePressed(MouseEvent e)
{}
/**
* The user clicked in the applet. Start the clock!
*/
public void mouseReleased(MouseEvent e) {
startSort();
e.consume();
}
public void mouseEntered(MouseEvent e)
{}
public void mouseExited(MouseEvent e)
{}
public String getAppletInfo() {
return "Title: ImageMap \nAuthor: James Gosling 1.17f, 10 Apr 1995 \nA simple applet class to demonstrate a sort algorithm. \nYou can specify a sorting algorithm using the 'alg' attribyte. \nWhen you click on the applet, a thread is forked which animates \nthe sorting algorithm.";
}
public String[][] getParameterInfo() {
String[][] info = {
{"als", "string", "The name of the algorithm to run. You can choose from the provided algorithms or suppply your own, as long as the classes are runnable as threads and their names end in 'Algorithm.' BubbleSort is the default. Example: Use 'QSort' to run the QSortAlgorithm class."}