Richards comment is short form what you've got to do:
create a function that you call before you create your GUI:
public String[] doLogin(){
JTextField name = new JTextField();
JPasswordField pwd = new JPasswordField();
Object[] message = { "Please enter Name and Password\n", name, pwd };
int iResponse = JOptionPane.showConfirmDialog(null, message, "Login",
JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
if(iResponse== JOptionPane.OK_OPTION) {
return new String[] {name.getText(), pwd.getPassword());
}
return null;
}