Skip to content

Instantly share code, notes, and snippets.

@manuelGitHub1
Created April 11, 2022 08:13
Show Gist options
  • Save manuelGitHub1/305bff0cf8dac794b27da26b19b2c4e8 to your computer and use it in GitHub Desktop.
Save manuelGitHub1/305bff0cf8dac794b27da26b19b2c4e8 to your computer and use it in GitHub Desktop.
Example for using two swing dialogs to capture login credentials
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