Start the animation with a mousePressed event
If an animation is already running, interrupt the thread to
terminate it
public class SelectionSortApplet extends Applet
{
public SelectionSortApplet()
{
class MousePressListener extends MouseAdapter
{
public void mousePressed(MouseEvent event)
{
if (animation != null && animation.isAlive())
animation.interrupt();
startAnimation();
}
}
MouseListener listener = new MousePressListener();
addMouseListener(listener);
. . .
animation = null;
}
. . .
private Thread Animation
}