packagecom.gui;importjava.awt.BorderLayout;publicclassUpDataextendsJDialogimplementsActionListener{privatefinalJPanelcontentPanel=newJPanel();privateJTextFieldtext_name;privateJPasswordFieldpasswordField_old;privateJPasswordFieldpasswordField_new;privateJPasswordFieldpasswordField_re;/***Launchtheapplication.*密码修改界面*/publicstaticvoidmain(String[]args){try{UpDatadialog=newUpData();dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);dialog.setVisible(true);}catch(Exceptione){e.printStackTrace();}}/***Createthedialog.*/publicUpData(){setTitle(\u4FEE\u6539\u5BC6\u7801);setResizable(false);setBounds(450,100,472,385);getContentPane().setLayout(newBorderLayout());contentPanel.setBorder(newEmptyBorder(5,5,5,5));getContentPane().add(contentPanel,BorderLayout.CENTER);JLabellblNewLabel=newJLabel(\u7528\u6237\u540D\uFF1A);lblNewLabel.setFont(newFont(宋体,Font.PLAIN,20));JLabellblNewLabel_1=newJLabel(\u65E7\u5BC6\u7801\uFF1A);lblNewLabel_1.setFont(newFont(宋体,Font.PLAIN,20));JLabellblNewLabel_2=newJLabel(\u65B0\u5BC6\u7801\uFF1A);lblNewLabel_2.setFont(newFont(宋体,Font.PLAIN,20));JLabellblNewLabel_3=newJLabel(\u786E\u5B9A\u5BC6\u7801\uFF1A);lblNewLabel_3.setFont(newFont(宋体,Font.PLAIN,20));text_name=newJTextField();text_name.setColumns(10);passwordField_old=newJPasswordField();passwordField_new=newJPasswordField();passwordField_re=newJPasswordField();JButtonbutton_submit=newJButton(\u786E\u8BA4\u4FEE\u6539);button_submit.setFont(newFont(宋体,Font.PLAIN,15));JButtonbutton_exit=newJButton(\u53D6\u6D88\u4FEE\u6539);button_exit.setFont(newFont(宋体,Font.PLAIN,15));button_submit.addActionListener(this);//注册监听button_exit.addActionListener(this);GroupLayoutgl_contentPanel=newGroupLayout(contentPanel);gl_contentPanel.setHorizontalGroup(gl_contentPanel.createParallelGroup(Alignment.LEADING).addGroup(gl_contentPanel.createSequentialGroup().addGap(71).addGroup(gl_contentPanel.createParallelGroup(Alignment.LEADING,false).addGroup(Alignment.TRAILING,gl_contentPanel.createSequentialGroup().addComponent(button_submit).addPreferredGap(ComponentPlacement.RELATED,GroupLayout.DEFAULT_SIZE,Short.MAX_VALUE).addComponent(button_exit)).addGroup(gl_contentPanel.createSequentialGroup().addGroup(gl_contentPanel.createParallelGroup(Alignment.LEADING).addComponent(lblNewLabel_1).addComponent(lblNewLabel).addComponent(lblNewLabel_2).addComponent(lblNewLabel_3)).addGap(9).addGroup(gl_contentPanel.createParallelGroup(Alignment.LEADING,false).addComponent(passwordField_re).addComponent(passwordField_old).addComponent(text_name,GroupLayout.DEFAULT_SIZE,188,Short.MAX_VALUE).addComponent(passwordField_new)))).addContainerGap(67,Short.MAX_VALUE)));gl_contentPanel.setVerticalGroup(gl_contentPanel.createParallelGroup(Alignment.LEADING).addGroup(gl_contentPanel.createSequentialGroup().addGap(20).addGroup(gl_contentPanel.createParallelGroup(Alignment.BASELINE).addComponent(lblNewLabel).addComponent(text_name,GroupLayout.PREFERRED_SIZE,GroupLayout.DEFAULT_SIZE,GroupLayout.PREFERRED_SIZE)).addGap(39).addGroup(gl_contentPanel.createParallelGroup(Alignment.BASELINE).addComponent(lblNewLabel_1).addComponent(passwordField_old,GroupLayout.PREFERRED_SIZE,20,GroupLayout.PREFERRED_SIZE)).addGap(32).addGroup(gl_contentPanel.createParallelGroup(Alignment.BASELINE).addComponent(lblNewLabel_2).addComponent(passwordField_new,GroupLayout.PREFERRED_SIZE,20,GroupLayout.PREFERRED_SIZE)).addGap(32).addGroup(gl_contentPanel.createParallelGroup(Alignment.BASELINE).addComponent(lblNewLabel_3).addComponent(passwordField_re,GroupLayout.PREFERRED_SIZE,20,GroupLayout.PREFERRED_SIZE)).addPreferredGap(ComponentPlacement.RELATED,32,Short.MAX_VALUE).addGroup(gl_contentPanel.createParallelGroup(Alignment.BASELINE).addComponent(button_exit).addComponent(button_submit)).addGap(37)));contentPanel.setLayout(gl_contentPanel);}@OverridepublicvoidactionPerformed(ActionEvente){//TODOAuto-generatedmethodstubStringbtnsString=e.getActionCommand();if(btnsString.equals(确认修改)){System.out.print(确认修改);StringnameString=text_name.getText().trim();Stringoldpassword=String.valueOf(passwordField_old.getPassword());Stringnewpassword=String.valueOf(passwordField_new.getPassword());Stringrepassword=String.valueOf(passwordField_re.getPassword());//密码修改if(!nameString.equals()&&repassword.equals(newpassword)&&!repassword.equals()&&!newpassword.equals()&&!oldpassword.equals()){System.out.print(相同);Userdateuserdate=newUserdate();Stringsql=updateuserdatasetuserpassword='+newpassword+'whereusername='+nameString+'anduserpassword='+oldpassword+';booleanflag=userdate.updataUser(sql);if(flag){JOptionPane.showMessageDialog(this,密码修改成功!);this.dispose();}else{JOptionPane.showMessageDialog(this,用户名与密码不符,请重试!);passwordField_old.setText();}}elseif(nameString.equals()){JOptionPane.showMessageDialog(this,用户名不能为空!);}elseif(oldpassword.equals()){JOptionPane.showMessageDialog(this,请输入旧密码!);}elseif(newpassword.equals()){JOptionPane.showMessageDialog(this,新密码不能为空!);System.out.print(新密码不能为空!);}elseif(repassword.equals()){JOptionPane.showMessa