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 mainMenu.java.    If you click the prizeCalculator button on this main menu, it opens the prizeCalculator JFrame window, which is located in an external class called prizeCalculator.java.  
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 = object1.new 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 mainMenu.java file: 

public class mainMenu
{
   public static void main(String[] args)
    {
        JFrame frame = new mainMenuFrame();
        frame.setVisible(true);
    }
}

class mainMenuFrame extends JFrame
{
    public mainMenuFrame()
    {
        setTitle("Main Menu");
        centerWindow(this);
        setResizable(false);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        JPanel panel = new mainMenuPanel();
        this.add(panel);
        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,
                        participantButton,
                        exitButton;
    
    public mainMenuPanel()
    {
       setLayout(new GridBagLayout());

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


//from the prizeCalculator.java 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");
        mainMenuButton.addActionListener(
                new ActionListener()
        {
            public void actionPerformed(ActionEvent e)
            {
            mainMenu object1 = new mainMenu();
            JFrame frame = object1.new mainMenuFrame();
            frame.setVisible(true);
            }
        });
        buttonPanel.add(mainMenuButton);

Open in new window

deeayrianAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mick BarryJava DeveloperCommented:
>             JFrame frame = object1.new mainMenuFrame();

should be:


            JFrame frame = new mainMenuFrame();
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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 = object1.new prizeCalculatorFrame();
            frame.setVisible(true);

But with this one I don't have to?
0
Mick BarryJava DeveloperCommented:
because in tht case the JFrame subclass is an inner class, thus you need to create an instance of the outer class
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.