⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 passwordpane.java

📁 课程设计:ATM Project源码
💻 JAVA
字号:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.util.Locale;
import java.util.Date;
import java.sql.*;
import java.text.*;
import javax.swing.border.*;
public class PasswordPane extends JPanel 
{  
   ReadAtmID idsource;
   Font fontword = new Font("楷体_GB2312",Font.BOLD,18);
   Font fontinput=new Font("Serif",Font.BOLD,18);
   JLabel l1=new JLabel("  卡  号:");
   JLabel l2=new JLabel("  原密码:");
   JLabel l3=new JLabel("  新密码:");
   JLabel l4=new JLabel("重复密码:");
   
   JLabel Title=new JLabel(new ImageIcon("..\\..\\title\\password.gif"));
   Font font=new Font("Serif",Font.BOLD,30);
   JTextField txtCard= new JTextField(10);
   JPasswordField txtPass= new JPasswordField(10);
   JPasswordField txtNew= new JPasswordField(10);
   JPasswordField txtAgain= new JPasswordField(10);
   JButton btConfirm=new JButton("修改");
   JButton btRead=new JButton("读卡");
   JButton btBack=new JButton("返回");
   Icon img=new ImageIcon(".\\gif\\ts.gif");

   Component f;
   private ActionListener listener=new ActionResponse();
   public PasswordPane (Component ComponentF)
   {
   	f=ComponentF;
   	idsource= new ReadAtmID(f);
   	this.setLayout(null);
   	this.setBorder(BorderFactory.createTitledBorder(
            BorderFactory.createLineBorder(Color.BLACK,1),
            "修改客户ATM卡密码",TitledBorder.CENTER,TitledBorder.TOP));

   	l1.setBounds(130,120,100,30);
   	l2.setBounds(130,150,100,30);
    l3.setBounds(130,180,100,30);
    l4.setBounds(130,210,100,30);
    l1.setFont(fontword);
    l2.setFont(fontword);
    l3.setFont(fontword);
    l4.setFont(fontword);
    l1.setForeground(Color.blue);
    l2.setForeground(Color.blue);
    l3.setForeground(Color.blue);
    l4.setForeground(Color.blue);
    txtCard.setBounds(220,125,150,20);
   	txtPass.setBounds(220,155,150,20);
   	txtNew.setBounds(220,185,150,20);
   	txtAgain.setBounds(220,215,150,20);
   	txtCard.setFont(fontinput);
   	txtPass.setFont(fontinput);
   	txtNew.setFont(fontinput);
   	txtAgain.setFont(fontinput);
   	btConfirm.setBounds(420,340,100,30);
   	btRead.setBounds(420,300,100,30);
   	btBack.setBounds(420,380,100,30);
   	btConfirm.setFont(fontinput);
   	btRead.setFont(fontinput);
   	btBack.setFont(fontinput);
   	Title.setBounds(50,20,490,100);
   	Title.setForeground(Color.red);
   	Title.setFont(font);
   	this.add(Title);
   	btConfirm.addActionListener(listener);
   	btRead.addActionListener(listener);
   	btBack.addActionListener(listener);

   	this.add(l1);
   	this.add(l2);
   	this.add(l3);
   	this.add(l4);
   	this.add(txtCard);
   	this.add(txtPass);
   	this.add(txtNew);
   	this.add(txtAgain);
   	this.add(btConfirm);
   	this.add(btRead);
   	this.add(btBack);
   }
   class ActionResponse implements ActionListener
   {
   	public void actionPerformed (ActionEvent e) 
    {
	 String cmd = e.getActionCommand();
	 if (cmd.equals("读卡"))
	{
       ReadAtmID CardReader = new ReadAtmID(f);
   	   txtCard.setText(String.valueOf(CardReader.ReadCardID()));
	}
	 if (cmd.equals("修改"))
	 {  
	  if(String.valueOf(txtNew.getPassword()).equals(String.valueOf(txtAgain.getPassword()))){
 try{
        String UserPwd="";
        String title = "请确定";
        int type = JOptionPane.INFORMATION_MESSAGE;
        SimpleDateFormat DateFormatter=new SimpleDateFormat("yyyy/MM/dd");
        String[] options={"是的","取消"};
        int optionType=JOptionPane.YES_NO_OPTION;
        int messageType=JOptionPane.QUESTION_MESSAGE; 
        String message = "真的要修改该卡的密码吗?";
        int result = JOptionPane.showOptionDialog(f,message, title, optionType,messageType,null,options,options[1]);
        if (result == JOptionPane.YES_OPTION)
        {
           Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
	       Connection c = DriverManager.getConnection("jdbc:odbc:accounts","","");
		   Statement s = c.createStatement();
           ResultSet r = s.executeQuery("SELECT * FROM Accounts WHERE CardID='"+txtCard.getText().trim()+"'");
	       while(r.next()) 
           {
	          UserPwd = new String(r.getString("Password"));
	       }
	      	if (UserPwd.equals(String.valueOf(txtPass.getPassword())))
	        {
	         	s.executeUpdate("UPDATE Accounts SET Password='"+String.valueOf(txtNew.getPassword())+"' WHERE CardID='"+txtCard.getText().trim()+"'");
	          	JOptionPane.showMessageDialog(f, "密码修改已经完成!\n","提示:", JOptionPane.INFORMATION_MESSAGE);
	        }
	        else
	        {
	            JOptionPane.showMessageDialog(f, "警告,密码错误,请重新输入!", "错误:", JOptionPane.INFORMATION_MESSAGE);
	        }    
	        s.close(); 
	     }
	    
	   
      }
      catch(SQLException Exp)
      {
      	JOptionPane.showMessageDialog(f, "输入值有误,请更正!", "错误:", JOptionPane.INFORMATION_MESSAGE);
      }
      catch(ClassNotFoundException Exp)
      {
      	JOptionPane.showMessageDialog(f, Exp.toString(), "错误:", JOptionPane.INFORMATION_MESSAGE);
      }
      catch(Exception Exp)
      {
      	JOptionPane.showMessageDialog(f,"卡号为 "+txtCard.getText()+" 的帐号不存在或已被注销!", "错误:", JOptionPane.INFORMATION_MESSAGE);
      }  
        }else{JOptionPane.showMessageDialog(f, "新输入的密码两次不一致!", "错误:", JOptionPane.INFORMATION_MESSAGE);}
       }  
    }
    
 
  }
}

  
		
	

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -