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

Posted on 2011-03-25
Medium Priority
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();
            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");
        JPanel panel = new prizeCalculatorPanel();

Open in new window

Question by:deeayrian
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 total points
ID: 35220778
           prizeCalculator object1 = new prizeCalculator();
            JFrame frame = object1.new prizeCalculatorFrame();
LVL 47

Expert Comment

ID: 35220783

What means:

object1.new prizeCalculatorFrame();

Author Closing Comment

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

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Having just graduated from college and entered the workforce, I don’t find myself always using the tools and programs I grew accustomed to over the past four years. However, there is one program I continually find myself reverting back to…R.   So …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to implement Singleton Design Pattern in Java.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses
Course of the Month10 days, 19 hours left to enroll

770 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