Remove .form so you do not run

1

Hi, I have an application in java that has a main and from this call to an interface that is with .form and .class once I create it I want with a button to access another screen and that this is eliminated but I can not get any advice what I have so far is the following:

 JFrame frame = new JFrame("UI");
                        frame.setContentPane(new UI().mainPanel);
                        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                        frame.pack();
                        frame.setVisible(true);
                        panel.setVisible(false);

I tried with dispose and it does not work for me either

    
asked by Berky 30.12.2018 в 20:49
source

1 answer

0

@Berky I hope this example serves you:

import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;

public class Application {

    public static void main(String[] args) {

        JFrame parent = new JFrame();
        parent.setLocationRelativeTo(null);
        parent.setSize(300,300);
        parent.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        parent.setLayout(new FlowLayout());

        JFrame child = new JFrame();
        child.setLocationRelativeTo(null);
        child.setSize(300,300);
        child.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        child.setLayout(new FlowLayout());

        JLabel label = new JLabel("child window");
        child.add(label);





        JButton button = new JButton("open child window");
        button.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                child.setVisible(true);
                parent.dispose();
            }
        });

        parent.add(button);
        parent.setVisible(true);
        parent.pack();

    }

}
    
answered by 30.12.2018 / 21:17
source