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.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 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"); loadItem.addActionListener(this); saveItem.addActionListener(this); exitItem.addActionListener(this); //loadItem.setIcon(loadIcon); //saveItem.setIcon(saveIcon); //exitItem.setIcon(exitIcon); fileMenu.setMnemonic(KeyEvent.VK_F); // Alt + f for file editMenu.setMnemonic(KeyEvent.VK_E); // Alt + e for edit helpMenu.setMnemonic(KeyEvent.VK_H); // Alt + h for help loadItem.setMnemonic(KeyEvent.VK_L); // l for load saveItem.setMnemonic(KeyEvent.VK_S); // s for save exitItem.setMnemonic(KeyEvent.VK_E); // 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); } } }
@Soyosan22
2 жыл бұрын
On a Mac these don't do anything :( : fileMenu.setMnemonic(KeyEvent.VK_F);//Alt + f for file editMenu.setMnemonic(KeyEvent.VK_E);//Alt + e for edit helpMenu.setMnemonic(KeyEvent.VK_H);//Alt + h for help
@EllieRParfitt
7 ай бұрын
its ctrl + option on a Mac. just spent ages working it out! can't get the load/save/exit item to work though, it selects them in the menu but doesn't execute the actions. so exit doesn't actually exit when i press e! just highlights it in the menu
@אהלןסהלן
2 жыл бұрын
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 👍
@zenonangelobarut7725
8 ай бұрын
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
@thephoenixsystem6765
2 жыл бұрын
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.
@draft_fusion
7 ай бұрын
When doing this I get arrows for my drop downs that point right, I am not sure what I did wrong.
@YTSHANKY
4 жыл бұрын
I like when you say.. hii whats up guys its bro here😀
@yeye7818
4 жыл бұрын
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 :)
@yeye7818
4 жыл бұрын
@@aproe610 I know, my first language was java, but recently i started learning C# because I wanna get into game development
@BroCodez
4 жыл бұрын
I lost motivation since that playlist wasn't receiving many views. Although I do have plans to go back and finish that playlist
@НікітаОрлов-с3ч
Жыл бұрын
You are the best. Thanks for lessons
@elionayzuridasilveira4140
2 ай бұрын
Thank you teacher for this video
@edelcrisostomo2566
3 жыл бұрын
Menu Listener how to function?
@katekate3246
3 жыл бұрын
How we can change the Icon`s size?
@AHPNY
4 жыл бұрын
Love the content Bro
@BroCodez
4 жыл бұрын
thanks for watching!
@defelo1590
Жыл бұрын
Hello,,,may we please have the link where you are downloading your imageicons from
@TuckerTheMandolinist
2 жыл бұрын
great tutorial, everything worked until i added the icons. How to fix?
@terrytoolin3285
4 ай бұрын
I thoroughly enjoyed your Java tutorial playlist.
@usamanadeem145
3 жыл бұрын
Thanks
@wizekhalifa1618
8 ай бұрын
Much respect ()
@eugenezuev7349
4 ай бұрын
*dropping comment below*
@whezboo
3 жыл бұрын
Thanks for your wisdom bro
@omgiheartpie
Жыл бұрын
You're awesome dude, thank you so much
@zari_723
2 жыл бұрын
:)))))))))
@RealEverythingComputers
5 ай бұрын
Thanks for the awesome video
@erikarrona3774
2 жыл бұрын
your videos have been a lot of help bro, thanks bro
@damiaofernandes9776
2 жыл бұрын
Muito bom que legal parece fácil vc fazendo
@code4031
2 жыл бұрын
👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍
@wombozombo
Жыл бұрын
comment
@MrLoser-ks2xn
2 жыл бұрын
Thanks
@damiaotiktok023
8 ай бұрын
Top muito bom mesmo 👏👏👏👏👏
@MmdRsh
Жыл бұрын
u are super hero man
@omartrkzi
2 жыл бұрын
For the algorithm
@pavelkvasnicka6856
Жыл бұрын
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
@Mirtguitar
Жыл бұрын
Good tutorial
@speklex779
11 ай бұрын
Nice video
@ibrahimylmaz8378
2 жыл бұрын
thanks bro
@greeneggsandmushrooms9855
3 жыл бұрын
drunkenn menu
@mediadimah22
3 жыл бұрын
Grazie per il tuo lavoro
@muhammedkabbani6434
2 жыл бұрын
really nice
@esqueletronesgomes1265
Жыл бұрын
❤❤
@henriquefelinimena3693
3 жыл бұрын
thank you for the content
@nawfalnjm5699
3 жыл бұрын
thank you
@YTSHANKY
4 жыл бұрын
Make c# toturial plz. But not for beginners it must be in intermediate level
@BroCodez
4 жыл бұрын
I will at some point, shouldn't take too long until then
Пікірлер: 57