Ulises CT
Ulises CT

Reputation: 1467

Launching a WindowApplication from another one in Java

I have a WindowApplication in Java named Login with a button to get into a menu once the user has entered is proper data.

How could I make it launch it another WindowApplication whose name is Prueba?

Do I also have to remove the main() method from the new windows to be launcher?

My current try for the button listener is

btnLogin.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                frmAdministracinHospital.setVisible(false);
                new Prueba();
            }
        });

but it's not working

Prueba class:

package presentacion;

import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import javax.swing.JComboBox;

public class Prueba {

    private JFrame frame;

    /**
     * Create the application.
     */
    public Prueba() {
        initialize();
    }

    /**
     * Initialize the contents of the frame.
     */

    private void initialize() {
        frame = new JFrame();
        frame.setBounds(100, 100, 450, 300);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        JPanel panel = new JPanel();
        frame.getContentPane().add(panel, BorderLayout.CENTER);

        JComboBox comboBox = new JComboBox();
        panel.add(comboBox);
    }

}

Any suggestions?

Thanks in advance!

Upvotes: 1

Views: 45

Answers (1)

Arnaud
Arnaud

Reputation: 17524

The frame of the Prueba class is never made visible .

All you have to do is to add frame.setVisible(true); at the end of your initialize() method, or at the end of your Prueba() constructor.

Upvotes: 1

Related Questions