1  import java.awt.*;
  2  import javax.swing.*;
  3  import java.util.concurrent.*;
  4  
  5  /**
  6     This program animates a sort algorithm.
  7  */
  8  public class AnimationTester
  9  {
 10     public static void main(String[] args)
 11     {
 12        JFrame frame = new JFrame();
 13        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 14  
 15        ArrayComponent panel = new ArrayComponent();
 16        frame.add(panel, BorderLayout.CENTER);
 17  
 18        frame.setSize(FRAME_WIDTH, FRAME_HEIGHT);
 19        frame.setVisible(true);
 20  
 21        Double[] values = new Double[VALUES_LENGTH];
 22        for (int i = 0; i < values.length; i++)
 23           values[i] = Math.random() * panel.getHeight();
 24  
 25        ExecutorService service = Executors.newCachedThreadPool();
 26        service.execute(new Sorter(values, panel));
 27     }
 28  
 29     private static final int VALUES_LENGTH = 30;
 30     private static final int FRAME_WIDTH = 300;
 31     private static final int FRAME_HEIGHT = 300;
 32  }