package jfconfig; /** * Created : Mar 7, 2012 * * @author pquiring */ import java.awt.Dimension; import java.awt.GraphicsEnvironment; import java.awt.Rectangle; import javaforce.*; public class GetPasswordDialog extends javax.swing.JDialog { /** * Creates new form GetPasswordDialog */ public GetPasswordDialog(java.awt.Frame parent, boolean modal) { super(parent, modal); initComponents(); setPosition(); } /** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { jLabel1 = new javax.swing.JLabel(); passwd1 = new javax.swing.JPasswordField(); jLabel2 = new javax.swing.JLabel(); passwd2 = new javax.swing.JPasswordField(); accept = new javax.swing.JButton(); cancel = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); jLabel1.setText("Password"); jLabel2.setText("Confirm"); accept.setText("Change Password"); accept.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { acceptActionPerformed(evt); } }); cancel.setText("Cancel"); cancel.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { cancelActionPerformed(evt); } }); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel1) .addComponent(jLabel2)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(passwd1) .addComponent(passwd2))) .addGroup(layout.createSequentialGroup() .addComponent(accept) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(cancel) .addGap(0, 0, Short.MAX_VALUE))) .addContainerGap()) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel1) .addComponent(passwd1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel2) .addComponent(passwd2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(accept) .addComponent(cancel)) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); pack(); }// </editor-fold>//GEN-END:initComponents private void acceptActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_acceptActionPerformed String p1 = getPassWord(); String p2 = getPassWord2(); if (p1.length() < 3) { JF.showError("Error", "Password too short"); return; } if (!p1.equals(p2)) { JF.showError("Error", "Passwords do not match"); return; } dispose(); }//GEN-LAST:event_acceptActionPerformed private void cancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelActionPerformed cancelled = true; dispose(); }//GEN-LAST:event_cancelActionPerformed // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton accept; private javax.swing.JButton cancel; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JPasswordField passwd1; private javax.swing.JPasswordField passwd2; // End of variables declaration//GEN-END:variables public boolean cancelled = false; public String getPassWord() {return new String(passwd1.getPassword());} public String getPassWord2() {return new String(passwd2.getPassword());} private void setPosition() { Rectangle s = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds(); Dimension d = getSize(); setLocation(s.width/2 - d.width/2, s.height/2 - (d.height/2)); } }