Skip to content

Commit e9b0ce5

Browse files
authored
New Things Added
1 parent 1b09e61 commit e9b0ce5

File tree

3 files changed

+153
-82
lines changed

3 files changed

+153
-82
lines changed

AlgorithmVisualizer.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
public class AlgorithmVisualizer {
2-
public static void main(String[] args){
3-
new Menu();
4-
}
5-
}
1+
public class AlgorithmVisualizer {
2+
public static void main(String[] args){
3+
new Menu();
4+
}
5+
}

Menu.java

+97-77
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,97 @@
1-
import java.awt.*;
2-
import javax.swing.*;
3-
import java.awt.event.*;
4-
5-
public class Menu extends JFrame {
6-
// Menubar
7-
static JMenuBar menuBar;
8-
9-
// JMenu
10-
static JMenu mainMenu, helpDesk;
11-
12-
// Menu items
13-
static JMenuItem menuItem1, menuItem2, menuItem3, menuItem4;
14-
15-
// A label
16-
static JLabel label;
17-
18-
Menu() {
19-
20-
// Create a label
21-
label = new JLabel("Welcome to Algorithm Visualizer!");
22-
23-
// Create a menubar
24-
menuBar = new JMenuBar();
25-
26-
// Create a menu
27-
mainMenu = new JMenu("Menu");
28-
helpDesk = new JMenu("Help");
29-
30-
// Create a menu items
31-
menuItem1 = new JMenuItem("Path Finding");
32-
menuItem2 = new JMenuItem("Sorting Techniques");
33-
menuItem3 = new JMenuItem("Puzzle Sorting");
34-
menuItem4 = new JMenuItem("How it Works");
35-
36-
ListenerClass listener = new ListenerClass();
37-
38-
// Register listeners
39-
menuItem1.addActionListener(listener);
40-
menuItem2.addActionListener(listener);
41-
menuItem3.addActionListener(listener);
42-
43-
// Add menu items to menu
44-
mainMenu.add(menuItem1);
45-
mainMenu.add(menuItem2);
46-
mainMenu.add(menuItem3);
47-
helpDesk.add(menuItem4);
48-
49-
// Add menu to menu bar
50-
menuBar.add(mainMenu);
51-
menuBar.add(helpDesk);
52-
53-
// Add menubar to frame
54-
setJMenuBar(menuBar);
55-
56-
// Add label
57-
add(label);
58-
59-
setTitle("EightSoft");
60-
setSize(400,400);
61-
// setLocation(200, 100);
62-
setVisible(true);
63-
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
64-
}
65-
66-
class ListenerClass implements ActionListener {
67-
String value;
68-
69-
// Project Main Logic (Moving Panels)
70-
public void actionPerformed(ActionEvent e) {
71-
if (e.getSource() == menuItem1) {
72-
label.setText("Wow Congratulations!");
73-
}
74-
}
75-
}
76-
77-
} // Menu
1+
import javax.swing.*;
2+
import java.awt.*;
3+
import java.awt.event.*;
4+
import java.util.*;
5+
6+
public class Menu extends JFrame {
7+
// Creating Object
8+
Sorting sort = new Sorting();
9+
10+
// Menubar
11+
static JMenuBar menuBar;
12+
13+
// JMenu
14+
static JMenu mainMenu, helpDesk;
15+
16+
// Menu items
17+
static JMenuItem menuItem1, menuItem2, menuItem3, menuItem4;
18+
19+
// A Panel
20+
static JPanel pPanel1, pPanel2;
21+
22+
Menu() {
23+
24+
// Create Panel
25+
pPanel1 = new JPanel();
26+
pPanel2 = new JPanel();
27+
28+
// Create a menubar
29+
menuBar = new JMenuBar();
30+
31+
// Create a menu
32+
mainMenu = new JMenu("Menu");
33+
helpDesk = new JMenu("Help");
34+
35+
// Create a menu items
36+
menuItem1 = new JMenuItem("Path Finding");
37+
menuItem2 = new JMenuItem("Sorting Techniques");
38+
menuItem3 = new JMenuItem("Puzzle Sorting");
39+
menuItem4 = new JMenuItem("How it Works");
40+
41+
ListenerClass listener = new ListenerClass();
42+
43+
// Register listeners
44+
menuItem1.addActionListener(listener);
45+
menuItem2.addActionListener(listener);
46+
menuItem3.addActionListener(listener);
47+
48+
// Add menu items to menu
49+
mainMenu.add(menuItem1);
50+
mainMenu.add(menuItem2);
51+
mainMenu.add(menuItem3);
52+
helpDesk.add(menuItem4);
53+
54+
// Add menu to menu bar
55+
menuBar.add(mainMenu);
56+
menuBar.add(helpDesk);
57+
58+
// Add menubar to frame
59+
setJMenuBar(menuBar);
60+
61+
// Add Panels
62+
pPanel1.setBackground(Color.CYAN);
63+
pPanel2.setBackground(Color.YELLOW);
64+
65+
// Add Panel
66+
pPanel1.add(sort.p1Sorting);
67+
pPanel2.add(sort.p2Sorting);
68+
sort.p1Sorting.setVisible(false);
69+
sort.p2Sorting.setVisible(false);
70+
71+
// Add Panels to the panel
72+
add(pPanel1, BorderLayout.WEST);
73+
add(pPanel2, BorderLayout.CENTER);
74+
75+
setTitle("EightSoft");
76+
setSize(700,500);
77+
setLocation(200, 100);
78+
setVisible(true);
79+
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
80+
}
81+
82+
class ListenerClass implements ActionListener {
83+
84+
// Project Main Logic (Moving Panels)
85+
public void actionPerformed(ActionEvent e) {
86+
if (e.getSource() == menuItem1) {
87+
sort.p1Sorting.setVisible(false);
88+
sort.p2Sorting.setVisible(false);
89+
}
90+
else if (e.getSource() == menuItem2) {
91+
sort.p1Sorting.setVisible(true);
92+
sort.p2Sorting.setVisible(true);
93+
}
94+
}
95+
}
96+
97+
} // Menu

Sorting.java

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import javax.swing.*;
2+
import java.awt.*;
3+
import java.awt.event.*;
4+
import java.util.*;
5+
6+
public class Sorting extends JFrame {
7+
// Values
8+
ArrayList<Integer> list=new ArrayList<Integer>();//Creating arraylist
9+
10+
// Sorting Buttons
11+
JButton jbtRandomize, jbtReset, jbtBubble, jbtInsertion, jbtSelection, jbtStart; // Sorting Buttons
12+
JPanel p1Sorting, p2Sorting;
13+
14+
// Random Creator
15+
Random rand = new Random();
16+
17+
// Progress Bar
18+
JProgressBar jb1;
19+
20+
Sorting(){
21+
// Buttons for sorting
22+
jbtRandomize = new JButton("Randomize");//create button
23+
jbtReset = new JButton("Reset");//create button
24+
jbtBubble = new JButton("Bubble sort");//create button
25+
jbtInsertion = new JButton("Insertion sort");//create button
26+
jbtSelection = new JButton("Selection sort");//create button
27+
jbtStart = new JButton("Start");//create button
28+
jbtStart.setBackground(Color.GREEN);
29+
30+
// Panel for buttons
31+
p1Sorting = new JPanel();
32+
p1Sorting.setLayout(new GridLayout(6,1));
33+
34+
// Adding Buttons to the panel
35+
p1Sorting.add(jbtRandomize); p1Sorting.add(jbtReset); p1Sorting.add(jbtSelection);
36+
p1Sorting.add(jbtBubble); p1Sorting.add(jbtInsertion); p1Sorting.add(jbtStart);
37+
38+
39+
jb1 = new JProgressBar(0,100);
40+
jb1.setValue(rand.nextInt(100));
41+
jb1.setStringPainted(true);
42+
43+
// Panel 2
44+
p2Sorting = new JPanel();
45+
p2Sorting.setLayout(new GridLayout(10,1));
46+
p2Sorting.add(jb1, BorderLayout.WEST);
47+
48+
}
49+
50+
}
51+

0 commit comments

Comments
 (0)