|
| 1 | +import javax.swing.*; |
| 2 | +import java.awt.*; |
| 3 | +import java.awt.event.*; |
| 4 | +import java.util.*; |
| 5 | + |
| 6 | +public class Sorting extends Main { |
| 7 | + // Values |
| 8 | + ArrayList<Integer> list=new ArrayList<Integer>();//Creating arraylist |
| 9 | + |
| 10 | + // Panels |
| 11 | + JPanel pPanel1, pPanel2; |
| 12 | + |
| 13 | + // Sorting Buttons |
| 14 | + JButton jbtRandomize, jbtReset, jbtBubble, jbtInsertion, jbtSelection, jbtStart; // Sorting Buttons |
| 15 | + |
| 16 | + // Random Creator |
| 17 | + Random rand = new Random(); |
| 18 | + |
| 19 | + // Progress Bar |
| 20 | + JProgressBar jb1; |
| 21 | + |
| 22 | + Sorting(){ |
| 23 | + // Create Panel |
| 24 | + // Panel for options (bubble sort, insertion sort...) |
| 25 | + pPanel1 = new JPanel(); |
| 26 | + pPanel1.setLayout(new GridLayout(6,1)); |
| 27 | + |
| 28 | + // Panel for main algorithm |
| 29 | + pPanel2 = new JPanel(); |
| 30 | + pPanel2.setLayout(new GridLayout(10,1)); |
| 31 | + |
| 32 | + // Buttons for sorting |
| 33 | + jbtRandomize = new JButton("Randomize");//create button |
| 34 | + jbtReset = new JButton("Reset");//create button |
| 35 | + jbtBubble = new JButton("Bubble sort");//create button |
| 36 | + jbtInsertion = new JButton("Insertion sort");//create button |
| 37 | + jbtSelection = new JButton("Selection sort");//create button |
| 38 | + jbtStart = new JButton("Start");//create button |
| 39 | + jbtStart.setBackground(Color.GREEN); |
| 40 | + |
| 41 | + // Progress bar |
| 42 | + jb1 = new JProgressBar(0,100); |
| 43 | + jb1.setValue(rand.nextInt(100)); |
| 44 | + jb1.setStringPainted(true); |
| 45 | + |
| 46 | + // Adding elements to Panel 1 |
| 47 | + pPanel1.add(jbtRandomize); pPanel1.add(jbtReset); pPanel1.add(jbtSelection); |
| 48 | + pPanel1.add(jbtBubble); pPanel1.add(jbtInsertion); pPanel1.add(jbtStart); |
| 49 | + |
| 50 | + // Adding elements to Panel 2 |
| 51 | + pPanel2.add(jb1, BorderLayout.WEST); |
| 52 | + |
| 53 | + // Set backgrounds for Panels |
| 54 | + pPanel1.setBackground(Color.CYAN); |
| 55 | + pPanel2.setBackground(Color.YELLOW); |
| 56 | + |
| 57 | + // pPanel1.add(p1Sorting); |
| 58 | + // pPanel2.add(p2Sorting); |
| 59 | + // p1Sorting.setVisible(true); |
| 60 | + // p2Sorting.setVisible(true); |
| 61 | + |
| 62 | + // Add Panels to the panel |
| 63 | + add(pPanel1, BorderLayout.NORTH); |
| 64 | + add(pPanel2, BorderLayout.CENTER); |
| 65 | + |
| 66 | + } |
| 67 | + |
| 68 | +} |
0 commit comments