Selection Sort Algorithm Animation: Implementation
- Use a lock to synchronize access to the shared state
- Add a component instance field to the algorithm class and augment the constructor to set it
- That instance field is needed for
- Repainting the component, and
- Finding out the dimensions of the component when drawing the algorithm state
public class SelectionSorter
{
public SelectionSorter(int[] anArray, JComponent aComponent)
{
a = anArray;
sortStateLock = new ReentrantLock();
component = aComponent;
}
. . .
private JComponent component;
}