Skip to content

Commit 0d6b30b

Browse files
committedDec 5, 2020
updated
1 parent 99bc805 commit 0d6b30b

File tree

4 files changed

+93
-5
lines changed

4 files changed

+93
-5
lines changed
 
File renamed without changes.

‎AlgorithmVisualizer.java

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import java.awt.*;
2+
import javax.swing.*;
3+
import java.awt.event.*;
4+
5+
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
78+
79+
public class AlgorithmVisualizer {
80+
public static void main(String[] args){
81+
new Menu();
82+
}
83+
}

‎menu1.java renamed to ‎ExampleMenu1.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import javax.swing.*;
66
import java.awt.event.*;
77

8-
public class menu1 extends JFrame implements ActionListener {
8+
public class ExampleMenu1 extends JFrame implements ActionListener {
99
// menubar
1010
static JMenuBar mb;
1111

@@ -22,10 +22,10 @@ public class menu1 extends JFrame implements ActionListener {
2222
static JLabel l;
2323

2424
// main class
25-
public static void main(String[] args){
25+
public static void main(String[] args) {
2626

2727
// create an object of the class
28-
menu1 m = new menu1();
28+
ExampleMenu1 m = new ExampleMenu1();
2929

3030
// create a frame
3131
f = new JFrame("Menu demo");

‎README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Algorithm Visualizer in Java
22

3-
By @Alimov-8 👨🏻‍💻 and @Rustam-Z 👨🏼‍💻
3+
By @Alimov-8👨🏻‍💻 and @Rustam-Z👨🏼‍💻
44

5-
🕐 Coming soon ...
5+
Updated: December 5, 2020
6+
7+
### References:
8+
- https://www.geeksforgeeks.org/java-swing-jmenubar/
9+
10+
- https://stackoverflow.com/questions/31094904/jmenu-not-appearing-until-window-is-resized

0 commit comments

Comments
 (0)