I would like to know how to go from one frame to another, executing the main of the other frame?

0

I would like to know how I go from one Jframe to another, executing the main of the other Jframe?

I have an input on the jframe that I want to open from the Jframe home, I open the following way the Jframe

Jframe2  abrir =new Jframe2();
abrir.setVisible(true);

But this way I do not run the main of that frame2, and I would like it to be shuffled because I have code to show.

    
asked by ya tu sabe 01.04.2018 в 18:52
source

1 answer

0

We create our first class:

public class PrimeraVentanaSwing {
    //Constructor
    PrimeraVentanaSwing(){
        muestraGUI();
    }

    private void muestraGUI(){
        JFrame.setDefaultLookAndFeelDecorated(true);
        JFrame marco = new JFrame("Hola mundo Swing");
        marco.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        marco.setPreferredSize(new Dimension(500,350));
        marco.setLocation(600, 500);
        marco.setVisible(true);
        marco.pack();
    }

    public static void main(String[] args) {

    }

}

Now we create our second class where we call both windows in the main

public class SegundaVentanaSwing {
    //Constructor
    SegundaVentanaSwing(){
        muestraGUI();
    }

    private void muestraGUI(){
        JFrame.setDefaultLookAndFeelDecorated(true);
        JFrame marco = new JFrame("Hola mundo Swing");
        marco.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        marco.setPreferredSize(new Dimension(500,350));
        marco.setLocation(650, 550);
        marco.setVisible(true);
        marco.pack();
    }

    public static void main(String[] args) {
        javax.swing.SwingUtilities.invokeLater(()->{
            PrimeraVentanaSwing pVS = new PrimeraVentanaSwing();
            SegundaVentanaSwing pVS2 = new SegundaVentanaSwing();
        });
    }

}

Result:

    
answered by 01.04.2018 в 19:45