package router; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.*; import javax.swing.GroupLayout.Alignment; import javax.swing.LayoutStyle.ComponentPlacement; /** * * @author mark */ public class PasswordDialog extends javax.swing.JDialog { /** * Creates new form PasswordDialog */ public PasswordDialog() { super((JDialog)null, true); initComponents(); getRootPane().setDefaultButton(btnOK); setLocationRelativeTo(null); setVisible(true); } /** * 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 JLabel(); jPasswordField1 = new JPasswordField(); btnOK = new JButton(); btnQuit = new JButton(); setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); setTitle("Deki Password"); jLabel1.setText("Enter your password:"); jLabel1.setName("jLabel1"); // NOI18N jPasswordField1.setName("jPasswordField1"); // NOI18N btnOK.setText("OK"); btnOK.setName("btnOK"); // NOI18N btnOK.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { btnOKActionPerformed(evt); } }); btnQuit.setText("Exit System"); btnQuit.setName("btnQuit"); // NOI18N btnQuit.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { btnQuitActionPerformed(evt); } }); GroupLayout layout = new GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addComponent(jLabel1) .addGap(0, 79, Short.MAX_VALUE)) .addComponent(jPasswordField1) .addGroup(Alignment.TRAILING, layout.createSequentialGroup() .addComponent(btnQuit) .addPreferredGap(ComponentPlacement.RELATED, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(btnOK))) .addContainerGap()) ); layout.setVerticalGroup( layout.createParallelGroup(Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addComponent(jLabel1) .addPreferredGap(ComponentPlacement.UNRELATED) .addComponent(jPasswordField1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) .addPreferredGap(ComponentPlacement.RELATED, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup(layout.createParallelGroup(Alignment.BASELINE) .addComponent(btnOK) .addComponent(btnQuit)) .addContainerGap()) ); pack(); }// </editor-fold>//GEN-END:initComponents private void btnQuitActionPerformed(ActionEvent evt) {//GEN-FIRST:event_btnQuitActionPerformed dispose(); }//GEN-LAST:event_btnQuitActionPerformed private void btnOKActionPerformed(ActionEvent evt) {//GEN-FIRST:event_btnOKActionPerformed dispose(); }//GEN-LAST:event_btnOKActionPerformed /** * @param args the command line arguments */ public String getPassword() { /* * Set the Nimbus look and feel */ //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) "> /* * If Nimbus (introduced in Java SE 6) is not available, stay with the * default look and feel. For details see * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html */ try { for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { javax.swing.UIManager.setLookAndFeel(info.getClassName()); break; } } } catch (ClassNotFoundException ex) { java.util.logging.Logger.getLogger(PasswordDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(PasswordDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(PasswordDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(PasswordDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } return new String(jPasswordField1.getPassword()); } // Variables declaration - do not modify//GEN-BEGIN:variables private JButton btnOK; private JButton btnQuit; private JLabel jLabel1; private JPasswordField jPasswordField1; // End of variables declaration//GEN-END:variables }