User420
User420

Reputation: 137

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. 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?
}                  

Upvotes: 0

Views: 60

Answers (1)

Braj
Braj

Reputation: 46841

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?

Upvotes: 2

Related Questions