本文整理汇总了Java中javax.swing.JPasswordField.setText方法的典型用法代码示例。如果您正苦于以下问题:Java JPasswordField.setText方法的具体用法?Java JPasswordField.setText怎么用?Java JPasswordField.setText使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.JPasswordField
的用法示例。
在下文中一共展示了JPasswordField.setText方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testAccountLoginValidation
import javax.swing.JPasswordField; //导入方法依赖的package包/类
/**
* Tests to ensure when a user attempts to log in that it correctly
* matches the hashed password stored in their account file.
* Will need to be updated once verifying something other than the label
* is possible (ie account functionality implemented).
*/
@Test
public void testAccountLoginValidation(){
JTextField usernameField = dlg.getUsernameField();
JPasswordField passPrimary = dlg.getPasswordFieldPrimary();
JPasswordField passVerify = dlg.getPasswordFieldVerify();
JButton button = dlg.getBtnSignIn();
try {
AccountManager.createUserAccount("BobTest", "guest");
} catch (IOException e) {
assertTrue(false);
e.printStackTrace();
}
//Test login to existing account via button
usernameField.setText("BobTest");
passPrimary.setText("guest");
button.doClick();
if(dlg.getErrorLabel().getText().equals("Successfully logged in.")){
assertTrue(true);
}
else{
assertTrue(false);
}
AccountManager.removeUserAccount("BobTest");
}
示例2: testAccountCreation
import javax.swing.JPasswordField; //导入方法依赖的package包/类
/**
* Tests to ensure account is not generated when it shouldn't be. For
* example: Differing passwords or account already exists. This does not
* validate the account creation process details.
*/
@Test
public void testAccountCreation() {
JTextField usernameField = dlg.getUsernameField();
JPasswordField passPrimary = dlg.getPasswordFieldPrimary();
JPasswordField passVerify = dlg.getPasswordFieldVerify();
JButton button = dlg.getBtnCreateNewAccount();
// Test account created no password
usernameField.setText("HeyTestGuy1");
passPrimary.setText("");
passVerify.setText("");
button.doClick();
assertTrue(AccountManager.userExists("HeyTestGuy1"));
// Test account NOT created - mismatched password
usernameField.setText("HeyTestGuy2");
passPrimary.setText("ardvark");
passVerify.setText("");
button.doClick();
assertFalse(AccountManager.userExists("HeyTestGuy2"));
//Test all correct values.
usernameField.setText("HeyTestGuy3");
passPrimary.setText("ardvark");
passVerify.setText("ardvark");
button.doClick();
assertTrue(AccountManager.userExists("HeyTestGuy3"));
assertTrue(AccountManager.removeUserAccount("HeyTestGuy1"));
assertTrue(AccountManager.removeUserAccount("HeyTestGuy3"));
}
示例3: 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);
}
}
示例4: passPane
import javax.swing.JPasswordField; //导入方法依赖的package包/类
/**
* Create the panel.
*/
public passPane(String name, String mail)
{
this.name = name;
this.mail = mail;
JLabel label = new JLabel("Wählen Sie ihr Passwort:");
passwordField = new JPasswordField();
passwordField.setColumns(15);
passwordField.setText(standardPassword);
passwordField_control = new JPasswordField();
passwordField_control.setColumns(15);
passwordField_control.setText(standardPassword);
btnWeiter = new JButton("weiter");
btnWeiter.setActionCommand("weiter");
btnWeiter.addActionListener(new ActionHandler());
btnAbbrechen = new JButton("abbrechen");
btnAbbrechen.setActionCommand("abbrechen");
btnAbbrechen.addActionListener(new ActionHandler());
errorLabel = new JLabel("Fehler!");
errorLabel.setForeground(Color.RED);
errorLabel.setVisible(false);
GroupLayout groupLayout = new GroupLayout(this);
groupLayout.setHorizontalGroup(groupLayout.createParallelGroup(Alignment.TRAILING)
.addGroup(groupLayout.createSequentialGroup().addContainerGap().addComponent(btnAbbrechen)
.addPreferredGap(ComponentPlacement.RELATED, 236, Short.MAX_VALUE).addComponent(btnWeiter)
.addContainerGap())
.addGroup(groupLayout.createSequentialGroup()
.addGroup(groupLayout.createParallelGroup(Alignment.TRAILING)
.addGroup(
groupLayout.createSequentialGroup().addContainerGap().addComponent(label,
GroupLayout.DEFAULT_SIZE, 309, Short.MAX_VALUE))
.addGroup(groupLayout.createSequentialGroup().addGap(152)
.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
.addComponent(passwordField_control, GroupLayout.PREFERRED_SIZE,
GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addComponent(passwordField))))
.addGap(129))
.addGroup(Alignment.LEADING, groupLayout.createSequentialGroup().addContainerGap()
.addComponent(errorLabel).addContainerGap(368, Short.MAX_VALUE)));
groupLayout.setVerticalGroup(groupLayout.createParallelGroup(Alignment.LEADING).addGroup(groupLayout
.createSequentialGroup().addContainerGap().addComponent(label).addGap(38)
.addComponent(passwordField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
GroupLayout.PREFERRED_SIZE)
.addGap(50)
.addComponent(passwordField_control, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
GroupLayout.PREFERRED_SIZE)
.addGap(45).addComponent(errorLabel)
.addPreferredGap(ComponentPlacement.RELATED, 50, Short.MAX_VALUE).addGroup(groupLayout
.createParallelGroup(Alignment.BASELINE).addComponent(btnWeiter).addComponent(btnAbbrechen))
.addContainerGap()));
setLayout(groupLayout);
}
示例5: DBMSConnectionWindow
import javax.swing.JPasswordField; //导入方法依赖的package包/类
public DBMSConnectionWindow(JFrame owner) {
super(owner);
dbmsList = new JComboBox<String>(DBMS_LIST);
hostname = new JTextField();
port = new JTextField();
username = new JTextField();
password = new JPasswordField();
nextButton = new JButton("✔ Next");
hostname.setText(DEFAULT_HOSTNAME);
port.setText(DEFAULT_PORT);
username.setText(DEFAULT_USERNAME);
password.setText(DEFAULT_PASSWORD);
dbmsList.setPreferredSize(new Dimension(TEXTFIELD_WIDTH, TEXTFIELD_HEIGHT));
hostname.setPreferredSize(new Dimension(TEXTFIELD_WIDTH, TEXTFIELD_HEIGHT));
port.setPreferredSize(new Dimension(TEXTFIELD_WIDTH, TEXTFIELD_HEIGHT));
username.setPreferredSize(new Dimension(TEXTFIELD_WIDTH, TEXTFIELD_HEIGHT));
password.setPreferredSize(new Dimension(TEXTFIELD_WIDTH, TEXTFIELD_HEIGHT));
JPanel mainContainer = new JPanel();
mainContainer.setLayout(new BoxLayout(mainContainer, BoxLayout.Y_AXIS));
mainContainer.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
JPanel dbmsPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
dbmsPanel.add(new JLabel("DBMS: "));
dbmsPanel.add(dbmsList);
JPanel hostnamePanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
hostnamePanel.add(new JLabel("Hostname: "));
hostnamePanel.add(hostname);
JPanel portPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
portPanel.add(new JLabel("Port: "));
portPanel.add(port);
JPanel usernamePanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
usernamePanel.add(new JLabel("Username: "));
usernamePanel.add(username);
JPanel passwordPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
passwordPanel.add(new JLabel("Password: "));
passwordPanel.add(password);
JPanel buttonsPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
buttonsPanel.add(nextButton);
mainContainer.add(dbmsPanel);
mainContainer.add(hostnamePanel);
mainContainer.add(portPanel);
mainContainer.add(usernamePanel);
mainContainer.add(passwordPanel);
mainContainer.add(buttonsPanel);
add(mainContainer);
buildWindow();
pack();
}