The problem with your code is that you added MenuBar
before declaring it. I'm not sure if your way of
adding a menubar is right/acceptable. Try using this
instead:
frame.setMenuBar(menubar);
Byt remember to declare the menubar first before
adding it.