Skip to content

Commit d7499e0

Browse files
committed
bug fixed - start after pressing button
1 parent 7ce8b43 commit d7499e0

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

Sorting.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,8 @@
44
import java.util.*;
55

66
public class Sorting extends Main {
7-
// the main drawings
87
SortingAlgorithm sortAlgo = new SortingAlgorithm();
98

10-
// Values
11-
ArrayList<Integer> list=new ArrayList<Integer>();//Creating arraylist
12-
139
// Panels
1410
JPanel pPanel1, pPanel2;
1511

@@ -80,12 +76,14 @@ else if (e.getSource() == jbtMerge)
8076
System.out.println("jbtMerge button clicked");
8177
else if (e.getSource() == jbtBubble)
8278
System.out.println("jbtBubble button clicked");
83-
else if (e.getSource() == jbtInsertion)
84-
new SortingAlgorithm(); // Sorting algotithm
79+
else if (e.getSource() == jbtInsertion) {
80+
sortAlgo.startSorting(); // Sorting algotithm
81+
}
8582
else if (e.getSource() == jbtSelection)
8683
System.out.println("jbtSelection button clicked");
87-
else if (e.getSource() == jbtStart)
84+
else if (e.getSource() == jbtStart) {
8885
System.out.println("jbtStart button clicked");
86+
}
8987

9088
// setVisible(false); // will close the previous window
9189
}

SortingAlgorithm.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
import java.awt.geom.Rectangle2D;
66
import java.util.Random;
77

8-
import javax.swing.JFrame;
98
import javax.swing.JPanel;
10-
import javax.swing.SwingUtilities;
119
import javax.swing.SwingWorker;
1210

1311
public class SortingAlgorithm extends JPanel {
@@ -22,6 +20,11 @@ public class SortingAlgorithm extends JPanel {
2220
setBackground(Color.BLACK);
2321
setPreferredSize(new Dimension(WIDTH, HEIGHT));
2422
initBarHeight(); // initialize the height of each bar
23+
//initSorter();
24+
initShuffler();
25+
}
26+
27+
public void startSorting() {
2528
initSorter();
2629
initShuffler();
2730
}
@@ -108,5 +111,4 @@ public void swap(int indexA, int indexB) {
108111
bar_height[indexA] = bar_height[indexB];
109112
bar_height[indexB] = temp;
110113
}
111-
112114
}

0 commit comments

Comments
 (0)