1

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!

Ulises CT
  • 1,361
  • 1
  • 12
  • 21
  • Please provide the code of the `Prueba` class . – Arnaud Dec 16 '16 at 13:14
  • Either add the 'Prueba' Aplication as dependecy to your 'login' Application, and call its start (`main`) method manually. Or use a procesBuilder to start it through a command. Note however that the command must differ based on the OS to work! – n247s Dec 16 '16 at 13:22
  • done... @Berger – Ulises CT Dec 16 '16 at 13:22
  • You have to make the `Prueba`'s frame visible : `frame.setVisible(true);` . – Arnaud Dec 16 '16 at 13:28
  • i get that the method setVisible(true) doesn't exist @Berger – Ulises CT Dec 16 '16 at 13:29
  • Yes I first thought `Prueba` was a `JFrame`, but it isn't. See my last comment . – Arnaud Dec 16 '16 at 13:31
  • 1) For better help sooner, post a [MCVE] or [Short, Self Contained, Correct Example](http://www.sscce.org/). 2) See [The Use of Multiple JFrames, Good/Bad Practice?](http://stackoverflow.com/q/9554636/418556) Note: A log-in should typically be displayed in a modal dialog or a `JOptionPane`. – Andrew Thompson Dec 16 '16 at 13:32
  • but what do i have to before that? I mean, I should declare a JFrame, a Prueba instance or...? @Berger – Ulises CT Dec 16 '16 at 13:34
  • 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 . – Arnaud Dec 16 '16 at 13:35
  • 1
    it worked thanks! you can add it as answer if you wish @Berger – Ulises CT Dec 16 '16 at 13:37

1 Answers1

1

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.

Arnaud
  • 17,229
  • 3
  • 31
  • 44