title: Java create menu in another class, add to frame
body: <p>I try to create a menu in Another class and add it to my frame, but it does not work (nothing adds). Can you help me see what is wrong with the code, thank you.</p>
  
  <p>Class Test: </p>
  
  <pre><code>public class Test extends JFrame {
  
      public Test() {                
          MenuBar menuBar = new MenuBar();                
          setJMenuBar(menuBar);            
          pack();
          setVisible(true);
      }
   }
  </code></pre>
  
  <p>Class Menu: </p>
  
  <pre><code>public class MenuBar extends JMenuBar {
  
      JMenuBar menuBar;
      JMenu menu;
  
      public MenuBar() {
          menuBar = new JMenuBar();
          menu = new JMenu("File");
          menuBar.add(menu);            
          MenuItem menuItem = new MenuItem();
          menu.add(menuItem);   
      }
  }
  </code></pre>
  
  <p>class MenuItem:</p>
  
  <pre><code>public class MenuItem extends JMenuItem {
  
      JMenuItem menuItemUndo;
      JMenuItem menuItemRedo;
  
      public MenuItem() {
          menuItemUndo = new JMenuItem("Undo");
          menuItemRedo = new JMenuItem("Redo");
      }    
   }
  </code></pre>