public char[] askPassword() { char[] password = null; final JDialog dlg = new JDialog(frm, "Password", true); final JPasswordField jpf = new JPasswordField(15); final JButton[] btns = {new JButton("Enter"), new JButton("Cancel")}; for (int i = 0; i < btns.length; i++) { btns[i].addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { dlg.setVisible(false); } }); } Object[] prts = new Object[] {"Please input a password:"******"Invalid password, passwords must be " + PASSWORD_MIN + " characters long"); System.exit(1); } return password; }
private void okActionPerformed(java.awt.event.ActionEvent evt) { if (smtp.getText().trim().isEmpty()) { CommonFunctions.showErrorMessage(this, "You must enter a SMTP server."); return; } else if (smtpUsername.getText().trim().isEmpty()) { CommonFunctions.showErrorMessage(this, "You must enter the SMTP username."); return; } else { try { int port = Integer.parseInt(smtpPort.getText()); if (port <= 0) throw new NumberFormatException(); new InternetAddress(email.getText()).validate(); } catch (NumberFormatException e) { CommonFunctions.showErrorMessage(this, "You must enter a valid SMTP port."); return; } catch (AddressException e) { CommonFunctions.showErrorMessage(this, "You must enter a valid source email address."); return; } } retval = 0; List<Student> selectedStudents = new ArrayList(); for (int i = 0; i < studentsTbl.getRowCount(); i++) { if ((boolean) studentsTbl.getValueAt(i, 0)) { selectedStudents.add(students.get(studentsTbl.convertRowIndexToModel(i))); } } output = new Object[] { email.getText(), smtp.getText(), smtpPort.getText(), smtpUsername.getText(), new String(smtpPassword.getPassword()), selectedStudents }; setVisible(false); }