Created
April 11, 2022 08:13
-
-
Save manuelGitHub1/305bff0cf8dac794b27da26b19b2c4e8 to your computer and use it in GitHub Desktop.
Example for using two swing dialogs to capture login credentials
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import javax.swing.*; | |
public class CredentialsDialog { | |
private String _email; | |
private String _password; | |
public String getEmail() { | |
return _email; | |
} | |
public String getPassword() { | |
return _password; | |
} | |
public void setEmail( String email ) { | |
_email = email; | |
} | |
public void setPassword( String password ) { | |
_password = password; | |
} | |
public void show() { | |
JTextField textField = new JTextField(); | |
int okOption = JOptionPane.showConfirmDialog(null, textField, "email", JOptionPane.OK_CANCEL_OPTION, | |
JOptionPane.PLAIN_MESSAGE); | |
if ( okOption == JOptionPane.OK_OPTION ) { | |
final String email = new String(textField.getText()); | |
// validation can be done here | |
_email = email; | |
} | |
JPasswordField passwordField = new JPasswordField(); | |
okOption = JOptionPane.showConfirmDialog(null, passwordField, "password", JOptionPane.OK_CANCEL_OPTION, | |
JOptionPane.PLAIN_MESSAGE); | |
if ( okOption == JOptionPane.OK_OPTION ) { | |
final String password = new String(passwordField.getPassword()); | |
_password = password; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment