Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7600891
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T23:01:38+00:00 2026-05-30T23:01:38+00:00

I have a netbeans Java application that should display a JFrame (class StartUpWindow extends

  • 0

I have a netbeans Java application that should display a JFrame (class StartUpWindow extends JFrame) with some options when the application is launched, then the user clicks a button and that JFrame should be closed and a new one (class MainWindow) should be opened.

So how do I do this correctly. I obviously set a click handler on the button in StartupWindow but what do I put in this handler so that I can close the StartUpWindow and open the MainWindow? It seems that threading comes into this too as every window seems to have their own thread…or are threading issues automatically handled by JFrames themselves…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T23:01:39+00:00Added an answer on May 30, 2026 at 11:01 pm

    Here is an example:

    enter image description here

    enter image description here

    StartupWindow.java

    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.SwingUtilities;
    
    
    public class StartupWindow extends JFrame implements ActionListener
    {
        private JButton btn;
    
        public StartupWindow()
        {
            super("Simple GUI");
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    
            btn = new JButton("Open the other JFrame!");
            btn.addActionListener(this);
            btn.setActionCommand("Open");
            add(btn);
            pack();
    
        }
    
        @Override
        public void actionPerformed(ActionEvent e)
        {
            String cmd = e.getActionCommand();
    
            if(cmd.equals("Open"))
            {
                dispose();
                new AnotherJFrame();
            }
        }
    
        public static void main(String[] args)
        {
            SwingUtilities.invokeLater(new Runnable(){
    
                @Override
                public void run()
                {
                    new StartupWindow().setVisible(true);
                }
    
            });
        }
    }
    

    AnotherJFrame.java

    import javax.swing.JFrame;
    import javax.swing.JLabel;
    
    public class AnotherJFrame extends JFrame
    {
        public AnotherJFrame()
        {
            super("Another GUI");
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    
            add(new JLabel("Empty JFrame"));
            pack();
            setVisible(true);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I learned today that NetBeans 6.5 should have an on-the-fly compilation of (single) Java
Java Newbie here. I have a JFrame that I added to my netbeans project,
Technology(Java EE 6 with Glassfish 3.1, Netbeans 7.0) I have an application client that
I have developed Java desktop application using Netbeans. In my application, I used some
I'm creating a Java application in NetBeans, and I have the following code that
I have a java web application that I am developing in Netbeans (and running
I have a small Java test app in Netbeans where the main() class reads
I am developing a standalone application, in Java using NetBeans, that gets and sends
All, I am having some trouble running a java web start application that has
I have created an application using Netbeans 6.9. In the application I want that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.