File tree Expand file tree Collapse file tree 2 files changed +22
-10
lines changed
Expand file tree Collapse file tree 2 files changed +22
-10
lines changed Original file line number Diff line number Diff line change @@ -17,11 +17,7 @@ public Main() {
1717 int [] list = new int [size ];
1818 for (int i = 0 ; i < list .length ; i ++) {
1919 list [i ] = i + 1 ;
20- //list[i] = size - i;
21- //list[i] = (size / 4) * (int)(1 + Math.random() * 4);
22- //list[i] = (size / 2);
2320 }
24- //list[(int)(Math.random() * size)] = size;
2521 //shuffle
2622 for (int i = 0 ; i < list .length ; i ++) {
2723 int index = (int ) (Math .random () * list .length );
@@ -45,15 +41,27 @@ public Main() {
4541 }
4642
4743 }
44+
45+ public void beginAnimation () {
46+ try {
47+ Thread .sleep (3000 );
48+ } catch (InterruptedException e ) {
49+ e .printStackTrace ();
50+ }
51+ for (int i = 0 ; i < sortPanels .length ; i ++) {
52+ sortPanels [i ].beginAnimation ();
53+ }
54+ }
4855
4956 public static void main (String [] args ) {
5057 JFrame frame = new JFrame ("Sorting Algorithm Animations" );
51- JApplet applet = new Main ();
52- frame .add (applet );
53- // frame.setUndecorated(true);
58+ Main main = new Main ();
59+ frame .add (main );
60+ frame .setUndecorated (true );
5461 frame .setDefaultCloseOperation (JFrame .EXIT_ON_CLOSE );
5562 frame .pack ();
5663 frame .setLocationRelativeTo (null );
5764 frame .setVisible (true );
65+ main .beginAnimation ();
5866 }
5967}
Original file line number Diff line number Diff line change 1111public abstract class SortPanel extends JPanel implements Runnable {
1212 private static final long serialVersionUID = 1L ;
1313 protected static final int BORDER_WIDTH = 10 ;
14- private static final Dimension PREFFERED_DIMENSION = new Dimension (440 , 340 );
14+ private static final Dimension PREFFERED_DIMENSION = new Dimension (640 , 360 );
1515 protected int size ;
1616 protected int [] list ;
1717 protected int sleepTime ;
1818 private String name ;
19+ private Thread thread ;
1920
2021 public SortPanel (String name , int [] list , int sleepTime ) {
2122 this .name = name ;
2223 this .size = list .length ;
2324 this .sleepTime = sleepTime ;
2425 this .list = java .util .Arrays .copyOf (list , size );
2526 setBackground (Color .BLACK );
26- Thread thread = new Thread (this );
27- thread .start ();
27+ thread = new Thread (this );
28+ }
29+
30+ public void beginAnimation () {
31+ thread .start ();
2832 }
2933
3034 @ Override
You can’t perform that action at this time.
0 commit comments