简体   繁体   English

单击JButton时如何打开新的JFrame?

[英]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 . 我有一个简单的问题, focalSumFrame在单击名为focalSum JButton时打开一个名为focalSumFrame的新JFrame I am working in netBeans IDE. 我在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. JDialogs和/或CardLayout用于程序的替代页面更加有效和容易。 Creating other JFrames to use as your pop-ups is a very ineffective way to go about what you're trying to do. 创建其他JFrames用作弹出窗口是执行您要执行的操作的一种非常无效的方法。

JDialog Information JDialog信息

Card Layout Information 卡布局信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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