本文整理匯總了Java中javax.swing.JPasswordField.getPassword方法的典型用法代碼示例。如果您正苦於以下問題:Java JPasswordField.getPassword方法的具體用法?Java JPasswordField.getPassword怎麽用?Java JPasswordField.getPassword使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.swing.JPasswordField
的用法示例。
在下文中一共展示了JPasswordField.getPassword方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: run
import javax.swing.JPasswordField; //導入方法依賴的package包/類
public static String run() { // SOURCE: https://goo.gl/5pFXao
JPanel panel = new JPanel();
JLabel label = new JLabel("This server is protected with a password.");
JPasswordField pass = new JPasswordField(10);
panel.add(label);
panel.add(pass);
String[] options = new String[]{"OK", "Cancel"};
int option = JOptionPane.showOptionDialog(null, panel, "Enter password",
JOptionPane.NO_OPTION, JOptionPane.PLAIN_MESSAGE,
null, options, options[0]);
if(option == 0) { // OK button
char[] password = pass.getPassword();
return new String(password);
} else {
return null;
}
}
示例2: showPasswordDialog
import javax.swing.JPasswordField; //導入方法依賴的package包/類
/**
* Show password dialog if enabled
*/
private String showPasswordDialog() {
JPanel panel = new JPanel(new BorderLayout());
JPasswordField pf = new JPasswordField();
panel.setBorder(new EmptyBorder(0, 10, 0, 10));
panel.add(pf, BorderLayout.NORTH);
JFrame frame = new JFrame();
frame.setAlwaysOnTop(true);
pf.requestFocus();
int option = JOptionPane.showConfirmDialog(frame, panel, I18n.get("main.start.sharelinkpwd"),
JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
frame.dispose();
if (option == JOptionPane.OK_OPTION) {
return new String(pf.getPassword());
} else {
return null;
}
}
示例3: inputPassword
import javax.swing.JPasswordField; //導入方法依賴的package包/類
@Override
public String inputPassword(String messageText) {
final JPasswordField passwordField = new JPasswordField();
JOptionPane jop = new JOptionPane(new Object[] { messageText, passwordField }, JOptionPane.QUESTION_MESSAGE,
JOptionPane.OK_CANCEL_OPTION);
JDialog dialog = jop.createDialog("Auhtentication required");
dialog.addComponentListener(new ComponentAdapter() {
@Override
public void componentShown(ComponentEvent e) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
passwordField.requestFocusInWindow();
passwordField.requestFocus();
}
});
}
});
dialog.setVisible(true);
int result = (Integer) jop.getValue();
if (result == JOptionPane.OK_OPTION) {
return new String(passwordField.getPassword());
} else {
return null;
}
}
示例4: showPasswordDialog
import javax.swing.JPasswordField; //導入方法依賴的package包/類
public static String showPasswordDialog(Component component, String text, String title) {
JPasswordField field = new JPasswordField(); field.setEchoChar('\u25CF');
JPanel panel = new JPanel();
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
panel.add(createLabel(text));
panel.add(field);
if(JOptionPane.showConfirmDialog(component, panel, title, JOptionPane.OK_CANCEL_OPTION)==JOptionPane.OK_OPTION)
return new String(field.getPassword());
else return null;
}
示例5: getCredential
import javax.swing.JPasswordField; //導入方法依賴的package包/類
Credential getCredential(String shost, String suser, String spass) {
JTextField host = new JTextField(shost);
JTextField user = new JTextField(suser);
JPasswordField pass = new JPasswordField(spass);
Object[] obj = new Object[6];
obj[0] = getString("HOST");
obj[1] = host;
obj[2] = getString("USER_NAME");
obj[3] = user;
obj[4] = getString("PASSWORD");
obj[5] = pass;
while (JOptionPane.showOptionDialog(null, obj, getString("LBL_CR"),
JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE,
null, null, null) == JOptionPane.OK_OPTION) {
if (host.getText() == null || host.getText().length() < 1) {
JOptionPane.showMessageDialog(null, getString("LBL_HOST"));
continue;
}
if (user.getText() == null || user.getText().length() < 1) {
JOptionPane.showMessageDialog(null, getString("LBL_USER"));
continue;
}
Credential c = new Credential();
c.host = host.getText();
c.user = user.getText();
c.pass = pass.getPassword().length > 0 ? new String(pass
.getPassword()) : null;
return c;
}
return null;
}
示例6: readFromGUI
import javax.swing.JPasswordField; //導入方法依賴的package包/類
/**
* Ask using a GUI for the username and password.
*/
private void readFromGUI() {
// Create fields for user name.
final JTextField usernameField = new JTextField(20);
usernameField.setText(this.username);
final JLabel usernameLabel = new JLabel("Username: ");
usernameLabel.setLabelFor(usernameField);
final JPanel usernamePane = new JPanel(new FlowLayout(FlowLayout.TRAILING));
usernamePane.add(usernameLabel);
usernamePane.add(usernameField);
// Create fields for password.
final JPasswordField passwordField = new JPasswordField(20);
passwordField.setText(this.password);
final JLabel passwordLabel = new JLabel("Password: ");
passwordLabel.setLabelFor(passwordField);
final JPanel passwordPane = new JPanel(new FlowLayout(FlowLayout.TRAILING));
passwordPane.add(passwordLabel);
passwordPane.add(passwordField);
// Create panel
final JPanel main = new JPanel();
main.setLayout(new BoxLayout(main, BoxLayout.PAGE_AXIS));
main.add(usernamePane);
main.add(passwordPane);
// Create and handle dialog
final JOptionPane jop = new JOptionPane(main, JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION);
final JDialog dialog = jop.createDialog("User name and password");
dialog.addComponentListener(new ComponentAdapter() {
public void componentShown(ComponentEvent e) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
if (usernameField.getText().isEmpty())
{
usernameField.requestFocusInWindow();
}
else
{
passwordField.requestFocusInWindow();
}
}
});
}
});
dialog.setVisible(true);
final Integer result = (Integer) jop.getValue();
dialog.dispose();
if (result.intValue() == JOptionPane.OK_OPTION) {
this.username = usernameField.getText();
final char[] pwd = passwordField.getPassword();
this.password = new String(pwd);
}
}