欢迎访问悦橙教程(wld5.com),关注java教程。悦橙教程  java问答|  每日更新
页面导航 : > > 文章正文

java,

来源: javaer 分享于  点击 48740 次 点评:29

java,


import java.sql.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

 

public class updapassword extends JFrame implements ActionListener {
 Connection con;
 Statement sql;
 
 JLabel lab1=null;
 JLabel lab2=null;
 JLabel lab3=null;
 TextField text1=null;
 TextField text2=null;
 TextField text3=null;
 JButton button1=null;
 JButton button2=null;
 updapassword(String s)
 {
  setLayout(null);
  setTitle("修改密码");
  Toolkit tool=this.getToolkit();
  Dimension dim=tool.getScreenSize();
  setBounds(300, 250, dim.width/2-130,dim.height/3);
  lab1=new JLabel("请输入旧密码:");
  lab1.setBounds(40, 0, 200, 100);
  lab1.setFont(new Font("Dialog",1,18));
  
  text1=new TextField();
  text1.setBounds(170, 35, 150, 25);
  text1.setEchoChar('*');
  
  
  lab2=new JLabel("请输入新密码:");
  lab2.setBounds(40, 40, 200, 100);
  lab2.setFont(new Font("Dialog",1,18));
  
  text2=new TextField();
  text2.setBounds(170, 75, 150, 25);
  text2.setEchoChar('*');
  
  lab3=new JLabel("请确认新密码:");
  lab3.setBounds(40, 80, 300, 100);
  lab3.setFont(new Font("Dialog",1,18));
  
  text3=new TextField();
  text3.setBounds(170, 115, 150, 25);
  text3.setEchoChar('*');
  
  button1=new JButton("修改");
  button1.setBounds(70, 165, 80, 25);
  button1.addActionListener(this);
  
  button2=new JButton("取消");
  button2.setBounds(220, 165, 80, 25);
  button2.addActionListener(this);
  
 
  add(lab1);
  add(text1);
  add(lab2);
  add(text2);
  add(lab3);
  add(text3);
  add(button1);
  add(button2);
  setResizable(false);
  setAlwaysOnTop(true);
  setVisible(true);
 }
 

 public void actionPerformed(ActionEvent e) {
  if(e.getActionCommand().equals("取消"))
  {
   setVisible(false);
  }
  else if(e.getActionCommand().equals("修改"))
  {
   try {
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    con=DriverManager.getConnection("jdbc:odbc:student","","");
    sql=con.createStatement();
    String s1,s2,s3=null;
    s1=text1.getText().trim();
    
   
    if(s1.equals(load.spwd))
    {
     s2=text2.getText().trim();
     s3=text3.getText().trim();
     if(s2.equals(s3))
     {
      sql.executeUpdate("update load set user_pwd='"+s2+"' where user_name='"+load.sname+"'");
      
      JOptionPane.showMessageDialog(this, "修改密码成功!", "修改密码提示框" , JOptionPane.INFORMATION_MESSAGE
                                      );
      setVisible(false);
     }
     else
     {
      JOptionPane.showMessageDialog(this, "对不起,两次输入的新密码不一致!", "修改密码提示框" , JOptionPane.INFORMATION_MESSAGE
        );
     }
    }
    else
    {
     JOptionPane.showMessageDialog(this, "对不起,旧密码错误!", "登陆提示框" , JOptionPane.INFORMATION_MESSAGE
       );
    }
     con.close();
    
   } catch (SQLException e1) {
     // TODO Auto-generated catch block
     e1.printStackTrace();
    
   } catch (ClassNotFoundException e1) {
    // TODO Auto-generated catch block
    e1.printStackTrace();
   }
  }  
 }
}

相关文章

    暂无相关文章
相关栏目:

用户点评