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

📄 lostpane.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 LostPane extends JPanel 
{  
   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\\lost.gif"));
Font font=new Font("Serif",Font.BOLD,30);

   JTextField txtCard= new JTextField(10);
   JTextField txtName= new JTextField(10);
   JPasswordField txtPwd= new JPasswordField(10);
   JTextField txtID= new JTextField(10);
   JButton btConfirm=new JButton("挂失");
   JButton btCancel=new JButton("取消");
   String UserPwd;
   String UserName;
   String UserCardID;
   Component f;
   private ActionListener listener=new ActionResponse();
   public LostPane (Component ComponentF)
   {
   	f=ComponentF;
   	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);
   	txtPwd.setBounds(220,185,150,20);
    txtName.setBounds(220,155,150,20);
    txtID.setBounds(220,215,150,20);
    txtCard.setFont(fontinput);
    txtPwd.setFont(fontinput);
    txtName.setFont(fontinput);
    txtID.setFont(fontinput);
   btConfirm.setBounds(420,300,100,30);
   	btCancel.setBounds(420,340,100,30);
   	btConfirm.setFont(fontinput);
   	btCancel.setFont(fontinput);
    Title.setBounds(50,20,490,100);
   	Title.setForeground(Color.red);
   	Title.setFont(font);
   	this.add(Title);
   	btConfirm.addActionListener(listener);
   	btCancel.addActionListener(listener);
   	this.add(l1);
   	this.add(l2);
   	this.add(l3);
   	this.add(l4);
   	this.add(txtCard);
   	this.add(txtPwd);
   	this.add(txtName);
   	this.add(txtID);		
   	this.add(btConfirm);
   	this.add(btCancel);
   }
class ActionResponse implements ActionListener
 {
  public void actionPerformed (ActionEvent e) 
  {  
	String cmd = e.getActionCommand();
	if (cmd.equals("挂失帐号"))
	{
   try{
	    String title = "提示";
        int type = JOptionPane.INFORMATION_MESSAGE;
        String[] options={"确定","取消"};
        int optionType=JOptionPane.YES_NO_OPTION;
        int messageType=JOptionPane.QUESTION_MESSAGE; 
        String message = "是否确定挂失该帐户的ATM卡?";
        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()+" AND Name='"+txtName.getText()+"'");
	    	while(r.next()) 
	    	{
	          UserPwd = new String(r.getString("Password"));
	          UserName = new String(r.getString("Name"));
	          UserCardID = new String(r.getString("CardID"));
	    	}
	    	if (UserPwd.equals(String.valueOf(txtPwd.getPassword())))
	          {
	          	s.executeUpdate("UPDATE Accounts SET LostFlag=TRUE WHERE CardID='"+txtCard.getText().trim()+"'");
	          	JOptionPane.showMessageDialog(f, "挂失操作已经完成!\n"+"帐号为  "+txtID.getText()+"  的客户资金已被冻结!", "提示:", 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,"警告!\n卡号为 "+txtCard.getText()+"\n姓名为"+txtName.getText()+"\n身份证号:"+txtID.getText()+"的ATM卡不存在或已被注销!", "错误:", JOptionPane.INFORMATION_MESSAGE);
      }
     }  
    }
    
   } 
  }
  
		
	

⌨️ 快捷键说明

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