Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

sub menus...

 
sae0203
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can i know how to create a sub menu bar... cause.. i really do not know how to implement it. below is the code ...
//menuBar
menuBar = new MenuBar();
m1 = new Menu("File");
m1.add("View");
m1.add("Create");
m1.add("Delete");
m1.add("Update");
m1.addSeparator();
m1.add("Exit");
m1.addActionListener(this);
m2 = new Menu("Help");
m2.add("About");
m2.add("Help Topics");
menuBar.add(m1);
menuBar.add(m2);
setMenuBar(menuBar);
i would like the view to have another 5 submenu... like customer, product, order, inventory and invoice.
like view--> customer
--> inventory
--> order
--> product
--> invoice
the tutorial from sun didn't help me solev the problem.
 
Priya Mahale
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Menu is a subclass of MenuItem so u can add menuitems as well as menus to a menu..
what u need to do is create a view menu ,add "customer", "inventory", etc. to the view menu and then add this view menu to the file menu..
I have pasted the sample code below..
Hope this helps u
import java.awt.*;
import javax.swing.*;
public class MenuDemo extends JFrame
{
MenuBar menuBar;
Menu fileMenu,helpMenu,viewMenu;
public MenuDemo()
{
menuBar = new MenuBar();
fileMenu = new Menu("File");
viewMenu = new Menu("View");
viewMenu.add("customer");
viewMenu.add("inventory");
viewMenu.add("order");
viewMenu.add("product");
viewMenu.add("invoice");
fileMenu.add(viewMenu);
fileMenu.add("Create");
fileMenu.add("Delete");
fileMenu.add("Update");
fileMenu.addSeparator();
fileMenu.add("Exit");
helpMenu = new Menu("Help");
helpMenu.add("About");
helpMenu.add("Help Topics");
menuBar.add(fileMenu);
menuBar.add(helpMenu);
setMenuBar(menuBar);

}
public static void main(String[] args)
{
MenuDemo menuDemo = new MenuDemo();
menuDemo.setSize(300,200);
menuDemo.setVisible(true);
}
}
 
sae0203
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you so much...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic