📄 changepasswordframe.java
字号:
/* * ChangePasswordFrame.java * * Created on 2008年5月7日, 下午8:27 */package javaproject;import java.io.*;import javax.swing.JOptionPane;/** * * @author Tian Fengping */public class ChangePasswordFrame extends javax.swing.JFrame { /** Creates new form ChangePasswordFrame */ public ChangePasswordFrame() { initComponents(); } /** 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. */ // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { jLabel1 = new javax.swing.JLabel(); jLabel2 = new javax.swing.JLabel(); oldJPasswordField = new javax.swing.JPasswordField(); firstNewJPasswordField = new javax.swing.JPasswordField(); oldJButton = new javax.swing.JButton(); firstNewJButton = new javax.swing.JButton(); jLabel3 = new javax.swing.JLabel(); secondNewJPasswordField = new javax.swing.JPasswordField(); secondNewJButton = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); setTitle("修改密码"); jLabel1.setText("输入旧密码:"); jLabel2.setText("输入新密码:"); firstNewJPasswordField.setEditable(false); oldJButton.setText("确定"); oldJButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { oldJButtonActionPerformed(evt); } }); firstNewJButton.setText("确定"); firstNewJButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { firstNewJButtonActionPerformed(evt); } }); jLabel3.setText("再输入一次新密码:"); secondNewJPasswordField.setEditable(false); secondNewJButton.setText("确定"); secondNewJButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { secondNewJButtonActionPerformed(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() .addComponent(jLabel3) .addGap(28, 28, 28)) .addGroup(layout.createSequentialGroup() .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, 145, Short.MAX_VALUE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)) .addGroup(layout.createSequentialGroup() .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(firstNewJPasswordField, javax.swing.GroupLayout.DEFAULT_SIZE, 155, Short.MAX_VALUE) .addComponent(oldJPasswordField, javax.swing.GroupLayout.PREFERRED_SIZE, 151, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(secondNewJPasswordField, javax.swing.GroupLayout.DEFAULT_SIZE, 155, Short.MAX_VALUE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(firstNewJButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(secondNewJButton, 0, 0, Short.MAX_VALUE) .addComponent(oldJButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addGap(23, 23, 23)) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(39, 39, 39) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(oldJButton) .addComponent(oldJPasswordField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel1)) .addGap(53, 53, 53) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel2) .addComponent(firstNewJPasswordField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(firstNewJButton)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 47, Short.MAX_VALUE) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel3) .addComponent(secondNewJButton) .addComponent(secondNewJPasswordField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(25, 25, 25)) ); pack(); }// </editor-fold>//GEN-END:initComponents PrintWriter input; BufferedReader output; File passwordFile; private void oldJButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_oldJButtonActionPerformed // TODO add your handling code here: String oldPassword=""; try { passwordFile = new File("Password.dat"); FileReader inputFile = new FileReader(passwordFile); output=new BufferedReader(inputFile); oldPassword=output.readLine(); } catch (IOException ex) { JOptionPane.showMessageDialog(null,"Make sure your input!"); } if(String.valueOf(oldJPasswordField.getPassword()).equals(oldPassword)) { firstNewJPasswordField.setEditable(true); } else { JOptionPane.showMessageDialog(null,"The password is wrong!Input again!","Wrong Password!",JOptionPane.WARNING_MESSAGE); }}//GEN-LAST:event_oldJButtonActionPerformed private void secondNewJButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_secondNewJButtonActionPerformed // TODO add your handling code here: if(String.valueOf(firstNewJPasswordField.getPassword()).equals(String.valueOf(secondNewJPasswordField.getPassword()))&&!String.valueOf(secondNewJPasswordField.getPassword()).equals("")) { try { passwordFile = new File("Password.dat"); FileWriter outputFile = new FileWriter(passwordFile); input=new PrintWriter(outputFile); input.println(String.valueOf(firstNewJPasswordField.getPassword())); input.close(); JOptionPane.showMessageDialog(null, "Successful!"); this.setVisible(false); } catch (IOException ex) { JOptionPane.showMessageDialog(null,"Make sure your input!"); } } else if(!String.valueOf(firstNewJPasswordField.getPassword()).equals(String.valueOf(secondNewJPasswordField.getPassword()))&&!String.valueOf(secondNewJPasswordField.getPassword()).equals("")) { JOptionPane.showMessageDialog(null,"The two inputs are differenet! Input again!","Wrong Input!",JOptionPane.WARNING_MESSAGE); } else if(String.valueOf(firstNewJPasswordField.getPassword()).equals(String.valueOf(secondNewJPasswordField.getPassword()))&&String.valueOf(secondNewJPasswordField.getPassword()).equals("")) { try { passwordFile = new File("Password.dat"); FileWriter outputFile = new FileWriter(passwordFile); input=new PrintWriter(outputFile); input.println(String.valueOf(firstNewJPasswordField.getPassword())); input.close(); } catch (IOException ex) { JOptionPane.showMessageDialog(null,"Make sure your input!"); } JOptionPane.showMessageDialog(null,"It has no password!","NO Password!",JOptionPane.WARNING_MESSAGE); JOptionPane.showMessageDialog(null, "Successful!"); this.setVisible(false); }}//GEN-LAST:event_secondNewJButtonActionPerformed private void firstNewJButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_firstNewJButtonActionPerformed // TODO add your handling code here: String firstNewPassword=String.valueOf(firstNewJPasswordField.getPassword()); secondNewJPasswordField.setEditable(true);}//GEN-LAST:event_firstNewJButtonActionPerformed /** * @param args the command line arguments */ public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new ChangePasswordFrame().setVisible(true); } }); } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton firstNewJButton; private javax.swing.JPasswordField firstNewJPasswordField; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JButton oldJButton; private javax.swing.JPasswordField oldJPasswordField; private javax.swing.JButton secondNewJButton; private javax.swing.JPasswordField secondNewJPasswordField; // End of variables declaration//GEN-END:variables }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -