Here is some code I made for you so you can see how you do it.
public class MenuBarShow extends JFrame implements ActionListener{
JMenuBar menuBar = new JMenuBar();
JMenu menu = new JMenu("A menu");
JMenuItem item;
public MenuBarShow(){
this.setVisible(true);
this.setLayout(new BorderLayout());
this.setSize(250,250);
this.setLocationRelativeTo(null);
this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
menu = new JMenu("A menu");
item = new JMenuItem("An item");
item.addActionListener(this);
menuBar.add(menu);
menu.add(item);
this.add(menuBar, BorderLayout.NORTH);
this.add(new JButton("Hello"), BorderLayout.CENTER);
}
@Override
public void actionPerformed(ActionEvent e) {
if(e.getSource() == item){
//Create new JFrame when pressing the JMenuItem
JFrame frame = new JFrame();
frame.setVisible(true);
frame.setLayout(new BorderLayout());
frame.setSize(250, 250);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.setVisible(true);
this.setVisible(false);
}
}
public static void main(String []args){
MenuBarShow mS = new MenuBarShow();
}
}
As you can see you just need to set the visible of the frame you have created to true and the previous frame visible to false. But there is a better way to handle it by using Cardlayout. You can find more about it here http://docs.oracle.com/javase/tutorial/uiswing/layout/card.html
Here is the same code using cardLayout.
public class MenuBarShow extends JFrame implements ActionListener{
JMenuBar menuBar = new JMenuBar();
JMenu menu = new JMenu("A menu");
JMenuItem item;
JPanel p = new JPanel(new CardLayout());
JPanel mainPanel = new JPanel(new BorderLayout());
CardLayout cl = new CardLayout();
JPanel showThisPanel = new JPanel();
public MenuBarShow(){
this.setVisible(true);
this.setLayout(new BorderLayout());
this.setSize(250,250);
this.setLocationRelativeTo(null);
this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
mainPanel.add(new JButton(BorderLayout.CENTER));
cl = (CardLayout)(p.getLayout());
p.add(showThisPanel, "STP");
p.add(mainPanel, "MP");
cl.show(p, "MP");
this.add(p);
menu = new JMenu("A menu");
item = new JMenuItem("An item");
item.addActionListener(this);
menuBar.add(menu);
menu.add(item);
this.add(menuBar, BorderLayout.NORTH);
}
@Override
public void actionPerformed(ActionEvent e) {
if(e.getSource() == item){
cl.show(p, "STP");
}
}
public static void main(String []args){
MenuBarShow mS = new MenuBarShow();
}