本文整理匯總了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();
}