How to open a new window from an external class in Java

I have an application that displays a main menu.  Then after clicking one of the buttons on the main menu, it should open a new window.  The code for the new JFrame to be displayed after clicking on the button, is in an external class.

How can I get this new window to display once the button is clicked?  Currently, the code I have doesn't respond to the button click. No errors are shown, but no new window is either.
//code in main class
public void actionPerformed(ActionEvent e)
    {
         Object source = e.getSource();
        if (source == exitButton)
            System.exit(0);
        else if (source == calculatorButton)
        {
            prizeCalculator object1 = new prizeCalculator();
            object1.new prizeCalculatorFrame();
       
        }
    }

// Code snippet from external class that contains new window code

public class prizeCalculator
{


 
class prizeCalculatorFrame extends JFrame
{
    public prizeCalculatorFrame()
    {
        setTitle("Prize Calculator");
        centerWindow(this);
        setResizable(false);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        JPanel panel = new prizeCalculatorPanel();
        this.add(panel);
        this.pack();
    }

Open in new window

deeayrianAsked:
Who is Participating?
 
objectsConnect With a Mentor Commented:
           prizeCalculator object1 = new prizeCalculator();
            JFrame frame = object1.new prizeCalculatorFrame();
            frame.setVisible(true);
           
0
 
for_yanCommented:
One thing that in constructore of your JFrame
you want to say

 this.setVisible(true);

or simpler

this.show();

I guess there are also other isues
0
 
for_yanCommented:

What means:

object1.new prizeCalculatorFrame();
0
 
deeayrianAuthor Commented:
Awesome!  Works perfectly.  Thanks SO much!
0
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.