Creating Menu and MenuItem using Java Swing
Creating Menu and MenuItem using Java Swing:
package Test;
import javax.swing.*;
class MenuAndMenuItem{
JMenu menu, submenu;
JMenuBar mb;
JMenuItem i1,i2,i3,i4,i5;
JFrame frame;
MenuAndMenuItem(){
frame = new JFrame("Menu and MenuItem Example");
menu = new JMenu("Menu");
submenu = new JMenu("Submenu");
mb = new JMenuBar();
i1 = new JMenuItem("Item 1");
i2 = new JMenuItem("Item 2");
i3 = new JMenuItem("Item 3");
i4 = new JMenuItem("Item 4");
i5 = new JMenuItem("Item 5");
menu.add(i1);
menu.add(i2);
menu.add(i3);
submenu.add(i4);
submenu.add(i5);
menu.add(submenu);
mb.add(menu);
frame.setSize(500,300);
frame.setLayout(null);
frame.setJMenuBar(mb);
frame.setVisible(true);
}
public static void main(String[] args) {
new MenuAndMenuItem();
}
}
YouTube
https://instagram.com/darkhers
https://www.facebook.com/darkhers
TikTok
https://www.tiktok.com/@darkhers
https://www.pinterest.co.uk/darkhers
Comments
Post a Comment