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

Posted on 2011-03-25
Last Modified: 2012-05-11
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)
        else if (source == calculatorButton)
            prizeCalculator object1 = new prizeCalculator();

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

public class prizeCalculator

class prizeCalculatorFrame extends JFrame
    public prizeCalculatorFrame()
        setTitle("Prize Calculator");
        JPanel panel = new prizeCalculatorPanel();

Open in new window

Question by:deeayrian
  • 2
LVL 47

Expert Comment

ID: 35220776
One thing that in constructore of your JFrame
you want to say


or simpler;

I guess there are also other isues
LVL 92

Accepted Solution

objects earned 500 total points
ID: 35220778
           prizeCalculator object1 = new prizeCalculator();
            JFrame frame = prizeCalculatorFrame();
LVL 47

Expert Comment

ID: 35220783

What means: prizeCalculatorFrame();

Author Closing Comment

ID: 35222097
Awesome!  Works perfectly.  Thanks SO much!

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
eclipse argument 14 61
hibernate example for saving data 19 44
null output 3 25
Android development question 2 38
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

825 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question