简体   繁体   English

调用JFrame并重新提示相同的JFrame

[英]Calling JFrame and reprompting the same JFrame

I would like add a simple code that will call the JFrame from the same package if its fullfill the if statement and if not it'll reprompt the same JFrame. 我想添加一个简单的代码,如果它完全填充了if语句,它将从同一包中调用JFrame,否则,它将重新提示相同的JFrame。 thanks. 谢谢。

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
    login lg = new login(username,password);
    boolean isMatches = lg.checkUser();
    if(isMatches) {
        Welcome WEL = new Welcome(); // How to call the Welcome JFrame
        WEL.setVisible(true);
    }
    else
        // How to make it reprompt the same JFrame?
}                  

Don't use multiple JFrame instead you can use CardLayout and can switch between different views. 不要使用多个JFrame而是可以使用CardLayout并可以在不同的视图之间切换。

The CardLayout class manages two or more components (usually JPanel instances) that share the same display space . CardLayout类管理共享相同显示空间的两个或更多组件(通常是JPanel实例)。

See Swing Tutorial on How to Use CardLayout and find a Demo as well. 请参阅有关如何使用CardLayout的 Swing教程 ,以及查找演示

For more info read The Use of Multiple JFrames, Good/Bad Practice? 有关更多信息,请阅读《使用多个JFrame,良好/不良做法?

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

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