Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit fd9cb27

Browse files
committed
changed to clean code
1 parent 1b09e61 commit fd9cb27

File tree

3 files changed

+82
-16
lines changed

3 files changed

+82
-16
lines changed

‎AlgorithmVisualizer.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
public class AlgorithmVisualizer {
22
public static void main(String[] args){
3-
new Menu();
3+
new Main();
44
}
55
}

‎Menu.java‎ renamed to ‎Main.java‎

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import javax.swing.*;
33
import java.awt.event.*;
44

5-
public class Menu extends JFrame {
5+
public class Main extends JFrame {
66
// Menubar
77
static JMenuBar menuBar;
88

@@ -12,14 +12,7 @@ public class Menu extends JFrame {
1212
// Menu items
1313
static JMenuItem menuItem1, menuItem2, menuItem3, menuItem4;
1414

15-
// A label
16-
static JLabel label;
17-
18-
Menu() {
19-
20-
// Create a label
21-
label = new JLabel("Welcome to Algorithm Visualizer!");
22-
15+
Main() {
2316
// Create a menubar
2417
menuBar = new JMenuBar();
2518

@@ -53,11 +46,8 @@ public class Menu extends JFrame {
5346
// Add menubar to frame
5447
setJMenuBar(menuBar);
5548

56-
// Add label
57-
add(label);
58-
59-
setTitle("EightSoft");
60-
setSize(400,400);
49+
setTitle("Eightsoft");
50+
setSize(800, 800);
6151
// setLocation(200, 100);
6252
setVisible(true);
6353
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
@@ -69,7 +59,15 @@ class ListenerClass implements ActionListener {
6959
// Project Main Logic (Moving Panels)
7060
public void actionPerformed(ActionEvent e) {
7161
if (e.getSource() == menuItem1) {
72-
label.setText("Wow Congratulations!");
62+
System.out.println("Menu Item 1 choosed");
63+
}
64+
else if (e.getSource() == menuItem2) {
65+
// Creating Object
66+
Sorting sort = new Sorting();
67+
System.out.println("Menu Item 2 choosed");
68+
}
69+
else if (e.getSource() == menuItem2) {
70+
System.out.println("Menu Item 3 choosed");
7371
}
7472
}
7573
}

‎Sorting.java‎

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /