The object of MenuItem class adds a simple labeled menu item on menu. The items used in a menu must belong to the MenuItem or any of its subclass.
This Java AWT code demonstrates how to create a Menu Bar using the AWT package in Java.
package awtDemo; import java.awt.*; import java.awt.event.*; //Menu Bar in AWT class MyApp extends Frame { public MyApp() { super("Tutor Joes"); setSize(1000, 600);// w,h setLayout(null); setVisible(true); MenuBar m=new MenuBar(); Menu menu=new Menu("Menu"); Menu submenu=new Menu("Sub Menu"); MenuItem i1=new MenuItem("Item 1"); MenuItem i2=new MenuItem("Item 2"); MenuItem i3=new MenuItem("Item 3"); MenuItem i4=new MenuItem("Item 4"); MenuItem i5=new MenuItem("Item 5"); menu.add(i1); menu.add(i2); menu.add(i3); submenu.add(i4); submenu.add(i5); menu.add(submenu); m.add(menu); setMenuBar(m); // Close Button Code this.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent we) { System.exit(0); } }); } } public class app { public static void main(String[] args) { MyApp frm = new MyApp(); } }To download raw file Click Here
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions