简体   繁体   中英

How to open new JFrame when clicking JButton?

I have a simple problem with opening a new JFrame called focalSumFrame while clicking on JButton called focalSum . I am working in netBeans IDE. My code looks like this:

private void focalSumActionPerformed(java.awt.event.ActionEvent evt) {                                         
    focalSumFrame.pack();
    focalSumFrame.setVisible(true);   
}

It's more efficent and easier to use JDialogs and/or CardLayout for alternative pages of your program. Creating other JFrames to use as your pop-ups is a very ineffective way to go about what you're trying to do.

JDialog Information

Card Layout Information

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM