简体   繁体   English

从一个JFrame移动到另一个JFrame

[英]Moving from one JFrame to another

In a package in Netbeans I created two JFrame Forms, first one is Login, second is, mainProgram, after the successful log in, I use the following way to "close" the Login frame and open the main program frame. 在Netbeans的一个包中我创建了两个JFrame Forms,第一个是Login,第二个是mainProgram,在成功登录后,我使用以下方式“关闭”Login框架并打开主程序框架。

mainProgram m=new mainProgram();
m.setVisible(true);
setVisible(false); //to hide the log in frame

Is this the correct way? 这是正确的方法吗? Isn't it wrong if these two separated classes are hidden instead of being closed? 如果这两个分开的类被隐藏而不是被关闭,这不是错的吗? are these one process or two different processes? 这是一个过程还是两个不同的过程? if there's a better way then what is it? 如果有更好的方法那么它是什么?

thanks.. 谢谢..

Is this the correct way? 这是正确的方法吗?

Yes, this should be fine. 是的,这应该没问题。

isn't it wrong if these 2 separated classes are hidden instead of being closed? 如果这两个分开的类被隐藏而不是被关闭,那不是错的吗?

The ideal is dispose of your unused forms (such as the login form when not needed any more) 理想的是处理您未使用的表格(例如不再需要时的登录表格)

are these 1 process or 2 different processes? 这1个过程还是2个不同的过程?

These will run on the same process 这些将在同一个进程上运行

In a package in Netbeans I created 2 JFrame Forms, first one is Login, second is, mainProgram, after the successful log in, I use the following way to "close" the Login frame and open the main program frame. 在Netbeans的一个包中我创建了2个JFrame Forms,第一个是Login,第二个是mainProgram,在成功登录后,我使用以下方式“关闭”Login框架并打开主程序框架。

use CardLayout , after correct login you can to switch the GUI to next Card and/or with change for JFrame Dimmnsion on the screen too, 使用CardLayout ,正确登录后,您可以将GUI切换到下一张卡和/或更改屏幕上的JFrame Dimmnsion,

in my opinion the more correct way is to use another class, like Launcher, which will have the entry point (main method). 在我看来,更正确的方法是使用另一个类,如Launcher,它将具有入口点(主方法)。 Make the login window as a modal JDialog, and set DISPOSE_ON_CLOSE as a value of default close operation . 将登录窗口设置为模式JDialog,并将DISPOSE_ON_CLOSE设置为默认关闭操作的值。 The class of dialog should contain a method to inform a user really logged in. After the login dialog is closed, show the main frame 对话框类应包含一个通知用户真正登录的方法。关闭登录对话框后,显示主框架

loginDialog.setVisible(true);
if (loginDialog.isLoggedIn())
    mainFrame.setVisible(true);

Try this... 尝试这个...

  1. The approach you used to hide and un-hide is fine, but will be better if dispose is used . 您曾经隐藏和取消隐藏的方法很好,但如果使用dispose则会更好

  2. Try applying the Singleton pattern on the classes which govern these JFrames. 尝试在管理这些JFrame的类上应用Singleton模式

  3. And yes they both will be on the same Process . 是的,他们都将在同一个过程中

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

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