You could do something like this:
import javax.swing.*;
public class Main {
public static void main(String[] args) {
boolean nameLocked = true;
String name;
name = JOptionPane.showInputDialog("Enter Your Name Please: ");
while (nameLocked) {
if (name.equals("fahad")) {
nameLocked = false;
passBox();
} else {
name = JOptionPane
.showInputDialog("Incorrect Username! Enter Your Name Please: ");
}
}
}
public static void passBox() {
boolean passLocked = true;
String passw;
while (passLocked) {
passw = JOptionPane.showInputDialog("Your Password: ");
if (passw.equals("123")) {
JOptionPane.showMessageDialog(null, "Successful Login");
passLocked = false;
}
else {
JOptionPane.showMessageDialog(null,
"Incorrect input, please exit or re enter password ");
}
}
}
}