www.pudn.com > st.rar > ChangePasswordDia.java


import java.awt.*; 
import java.awt.event.*; 
import javax.swing.*; 
 
import java.util.*; 
import java.sql.*; 
 
 
public class ChangePasswordDia extends JDialog implements ActionListener{ 
	 
	JButton b1=new JButton("确定"); 
	JButton b2=new JButton("取消"); 
	JTextField tf1=new JTextField(13); 
	JPasswordField pf1=new JPasswordField(13); 
	JPasswordField pf2=new JPasswordField(13); 
	 
	 
////////// 
	String sql;  
    Connection conn;  
    Statement stmt;  
    ResultSet rs; 
	 
	ChangePasswordDia(){ 
	 
		Container contentPane=this.getContentPane(); 
		contentPane.setBackground(Color.white); 
		contentPane.setLayout(null); 
		contentPane.add(b1);contentPane.add(b2); 
		contentPane.add(tf1); 
		contentPane.add(pf1); 
		contentPane.add(pf2); 
	 
		JLabel l[]=new JLabel[3]; 
		l[0]=new JLabel("帐号"); 
		l[1]=new JLabel("密码"); 
		l[2]=new JLabel("重复密码"); 
		contentPane.add(l[0]);contentPane.add(l[1]);contentPane.add(l[2]); 
		contentPane.add(b1);contentPane.add(b2); 
		////////// 
		l[0].setBounds(20, 20, 100, 30); 
		l[1].setBounds(20, 60, 100, 30); 
		l[2].setBounds(20, 100, 100, 30); 
		tf1.setBounds(130, 20, 100, 30); 
		pf1.setBounds(130, 60, 100, 30); 
		pf2.setBounds(130, 100, 100, 30); 
		b1.setBounds(50, 150, 100, 30); 
		b2.setBounds(160, 150, 100, 30); 
		//////// 
		b1.addActionListener(this); 
		b2.addActionListener(this); 
        setModal(true); 
		setTitle("修改帐号与密码"); 
		setSize(300,250); 
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); 
		Dimension screen=Toolkit.getDefaultToolkit().getScreenSize(); 
		setLocation((screen.width-300)/2,(screen.height-250)/2); 
		setVisible(true); 
		 
	} 
 
	public void actionPerformed(ActionEvent e){ 
		if(e.getSource()==b1){ 
			if(pf1.getText().equals(pf2.getText())){ 
			try{ 
				 
				Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");  
				String url="jdbc:odbc:SUMMIT";  
				String user="sa";  
				String password="198662";  
				conn= DriverManager.getConnection(url,user,password); 
				stmt=conn.createStatement();  
				sql="update Teacher set ID='"+tf1.getText()+"'"; 
				sql=sql+",PASSWORD='"+pf1.getText()+"'"; 
				if(stmt.executeUpdate(sql)==1){ 
					JOptionPane.showMessageDialog(null, "修改成功"); 
					dispose();} 
				else { 
					JOptionPane.showMessageDialog(null, "修改失败"); 
					tf1.requestFocus(); 
				} 
	 
				conn.close(); 
				stmt.close();		 
		       }catch(Exception e1){JOptionPane.showMessageDialog(null,e1.getMessage());}} 
		} 
		if(e.getSource()==b2){ 
			dispose(); 
		} 
	} 
	 
	 
	 
 
}