Java menubar 🗄️

preview_player
Показать описание
Java menubar JMenuBar

#Java #menubar #JMenuBar
Рекомендации по теме
Комментарии
Автор

public class Main{

public static void main(String[] args) {

new MyFrame();
}
}
import java.awt.FlowLayout;
import java.awt.event.*;
import javax.swing.*;

public class MyFrame extends JFrame implements ActionListener{

JMenuBar menuBar;
JMenu fileMenu;
JMenu editMenu;
JMenu helpMenu;
JMenuItem loadItem;
JMenuItem saveItem;
JMenuItem exitItem;
//ImageIcon loadIcon;
//ImageIcon saveIcon;
//ImageIcon exitIcon;

MyFrame(){

this.setSize(100, 100);
this.setLayout(new FlowLayout());

//loadIcon = new ImageIcon("load.png");
//saveIcon = new ImageIcon("save.png");
//exitIcon = new ImageIcon("exit.png");

menuBar = new JMenuBar();

fileMenu = new JMenu("File");
editMenu = new JMenu("Edit");
helpMenu = new JMenu("Help");

loadItem = new JMenuItem("Load");
saveItem = new JMenuItem("Save");
exitItem = new JMenuItem("Exit");









// Alt + f for file
// Alt + e for edit
// Alt + h for help
// l for load
// s for save
// e for exit

fileMenu.add(loadItem);
fileMenu.add(saveItem);
fileMenu.add(exitItem);

menuBar.add(fileMenu);
menuBar.add(editMenu);
menuBar.add(helpMenu);

this.setJMenuBar(menuBar);

this.setVisible(true);
}

@Override
public void actionPerformed(ActionEvent e) {

if(e.getSource()==loadItem) {
System.out.println("*beep boop* you loaded a file");
}
if(e.getSource()==saveItem) {
System.out.println("*beep boop* you saved a file");
}
if(e.getSource()==exitItem) {
System.exit(0);
}
}
}

BroCodez
Автор

I thoroughly enjoyed your Java tutorial playlist.

terrytoolin
Автор

Awesome tutorial man! Unfortunately when I went by your idea of implementing the listen, just in an inner class, the listener didn't respond to the events at all :(, ended up making individual listeners for each of the fields of my class, wich solved the problem 👍

אהלןסהלן
Автор

Muito bom que legal parece fácil vc fazendo

damiaofernandes
Автор

This is the best Java tutorial for beginners, so you can learn Java and English in one hit. Please keep going! I vote for Java advance tutorial. Thanks a lot Bro

pavelkvasnicka
Автор

You're awesome dude, thank you so much

omgiheartpie
Автор

Thanks for the tut, this'll save me a lot of bother!
Question - do you create your own icons or find/buy them? I'm having trouble finding uniform-style icon sets so I've started to build my own.

thephoenixsystem
Автор

I like when you say.. hii whats up guys its bro here😀

YTSHANKY
Автор

your videos have been a lot of help bro, thanks bro

erikarrona
Автор

Why are you not making videos about other languages, for example why are you no longer making videos about C#? (I'm sorry if you've already said why, i started watching your C# series a couple of days ago). Btw your tutorials are very helpful and fun to watch, thank you for making them :)

yeye
Автор

When doing this I get arrows for my drop downs that point right, I am not sure what I did wrong.

draft_fusion
Автор

Hey, Bro! I hope you will read this but my icons were always big. I'm using eclipse 2023 and also the sysout ctrl + space shortcut can only use 1 time. Please help me

zenonangelobarut
Автор

Hello, , , may we please have the link where you are downloading your imageicons from

defelo
Автор

Make c# toturial plz. But not for beginners it must be in intermediate level

YTSHANKY