Source of AnimationTester.java


  1: import java.awt.*;
  2: import javax.swing.*;

  4: /**
  5:    This program animates a sort algorithm.
  6: */
  7: public class AnimationTester
  8: {
  9:    public static void main(String[] args)
 10:    {
 11:       JFrame frame = new JFrame();
 12:       frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

 14:       ArrayComponent panel = new ArrayComponent();
 15:       frame.add(panel, BorderLayout.CENTER);

 17:       frame.setSize(FRAME_WIDTH, FRAME_HEIGHT);
 18:       frame.setVisible(true);

 20:       Double[] values = new Double[VALUES_LENGTH];
 21:       for (int i = 0; i < values.length; i++)
 22:          values[i] = Math.random() * panel.getHeight();

 24:       Runnable r = new Sorter(values, panel);
 25:       Thread t = new Thread(r);
 26:       t.start();
 27:    }

 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: }