Opening a JFrame window by calling an external class

I have a main menu that displays when the program is started.  It is located in the main method and class called    If you click the prizeCalculator button on this main menu, it opens the prizeCalculator JFrame window, which is located in an external class called  
There is a button on the prizeCalculator window that says "main menu" and when clicked, should close the prizeCalculator window and display the mainMenu window again.  

In the prizeCalculator external class, this line of code:
JFrame frame = mainMenuFrame();  
is giving the error that mainMenuFrame() is not recognized.  

Can you help me show the main menu frame once the "main menu" button is clicked on the prizeCalculator window?    Code and images are attached
 menu.tiff panel.tiff
//From the file: 

public class mainMenu
   public static void main(String[] args)
        JFrame frame = new mainMenuFrame();

class mainMenuFrame extends JFrame
    public mainMenuFrame()
        setTitle("Main Menu");
        JPanel panel = new mainMenuPanel();
        setSize(200, 200);

    private void centerWindow(Window w)
        Toolkit tk = Toolkit.getDefaultToolkit();
        Dimension d = tk.getScreenSize();
        setLocation((d.width-w.getWidth())/2, (d.height-w.getHeight())/2);

class mainMenuPanel extends JPanel implements ActionListener

    private JButton     calculatorButton,
    public mainMenuPanel()
       setLayout(new GridBagLayout());

        // display panel
        JPanel displayPanel = new JPanel();
        displayPanel.setLayout(new FlowLayout(FlowLayout.CENTER));
// and so on......

//from the file   This is the part that is telling the main menu button to show the main menu again

// main menu button
        mainMenuButton = new JButton("Main Menu");
                new ActionListener()
            public void actionPerformed(ActionEvent e)
            mainMenu object1 = new mainMenu();
            JFrame frame = mainMenuFrame();

Open in new window

Who is Participating?
objectsConnect With a Mentor Commented:
>             JFrame frame = mainMenuFrame();

should be:

            JFrame frame = new mainMenuFrame();
deeayrianAuthor Commented:
Thank you that works perfectly!
But, I have a question.  How come when I needed to show the prizeCalculator JFrame from the main menu window, I had to create a new object, like this:
            prizeCalculator object1 = new prizeCalculator();
            JFrame frame = prizeCalculatorFrame();

But with this one I don't have to?
because in tht case the JFrame subclass is an inner class, thus you need to create an instance of the outer class
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.