title: Adding a submenu
body: <p>So I tried to look at the Java docs for help for this but got confused pretty quickly. I am trying to add a submenu to the menu item 'Edit' which will have submenus Copy and Paste, and I'm note sure how to do it. I have a submenu variable created, do I use that? Please help, thank you. Code is below.</p>
  
  <pre><code>import javax.swing.JFrame;
  import javax.swing.JMenuBar;
  import javax.swing.JMenu;
  import javax.swing.JMenuItem;
  
  public class MyJFrame extends JFrame
  {
  JMenuBar menubar;
  JMenu menu, submenu;
  JMenuItem mi;
  
  public MyJFrame(String title)
  {
      super(title);
      menubar = new JMenuBar();
      setJMenuBar(menubar);
      buildMenu();
  }
  
  void buildMenu()
  {
  menu = new JMenu("File");
  
             mi = new JMenuItem("New");
             menu.add(mi);
             menubar.add(menu);
  
             mi = new JMenuItem("List Files");
             menu.add(mi);
             menubar.add(menu);
             menu.addSeparator();
  
             mi = new JMenuItem("Save As");
             menu.add(mi);
             menubar.add(menu);
             menu.addSeparator();
  
             mi = new JMenuItem("Close");
             menu.add(mi);
             menubar.add(menu);
  
      menu = new JMenu("Tools");
  
             mi = new JMenuItem("Sort");
             menu.add(mi);
             menubar.add(menu);
  
             mi = new JMenuItem("Search");
             menu.add(mi);
             menubar.add(menu);
  
             mi = new JMenuItem("Edit");
             menu.add(mi);
             menubar.add(menu);
             mi = new JMenuItem("Copy");
             menu.add(mi);
             menubar.add(menu);
             mi = new JMenuItem("Paste");
             menu.add(mi);
             menubar.add(menu);
  }
  }
  </code></pre>