0

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. 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?
}                  
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
User420
  • 137
  • 3
  • 12

1 Answers1

2

Don't use multiple JFrame instead you can use CardLayout and can switch between different views.

The CardLayout class manages two or more components (usually JPanel instances) that share the same display space.

See Swing Tutorial on How to Use CardLayout and find a Demo as well.

For more info read The Use of Multiple JFrames, Good/Bad Practice?

Community
  • 1
  • 1
Braj
  • 46,415
  • 5
  • 60
  • 76
  • Since a log-in panel is typically much smaller than a main GUI, it is well suited to a (possibly) modal dialog or a `JOptionPane`. An [e.g of the latter](http://stackoverflow.com/a/10773412/418556). – Andrew Thompson Jul 21 '14 at 08:15
  • 1
    @AndrewThompson yes I agree with you and for other views we can use JPanel. – Braj Jul 21 '14 at 08:17
  • 1
    True. And even if using a dialog in this instance for the log-in itself, you might use a `CardLayout` to flip from a 'splash' style image in the main UI before log-in, to the GUI proper after log-in. – Andrew Thompson Jul 21 '14 at 08:30