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

📄 pickpane.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 PickPane 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 Title=new JLabel(new ImageIcon("..\\..\\title\\pick.gif"));
   Font font=new Font("Serif",Font.BOLD,30);
   JTextField txtCard= new JTextField(10);
   JPasswordField txtPwd= new JPasswordField(10);
   JTextField txtMoney= new JTextField(10);
   JButton btConfirm=new JButton("读卡");
   JButton btCancel=new JButton("取款");
   JButton btBack=new JButton("取消");
   String UserPwd;
   String UserName;
   Component f;
   private ActionListener listener=new ActionResponse();
   public PickPane (Component ComponentF)
   {
   	f=ComponentF;
   	this.setLayout(null);
   	this.setBorder(BorderFactory.createTitledBorder(
            BorderFactory.createLineBorder(Color.BLACK,1),
      "取款操作系统",TitledBorder.CENTER,TitledBorder.TOP));
   	l1.setBounds(130,120,100,30);
   	l2.setBounds(130,150,100,30);
    l3.setBounds(130,180,100,30);
    l1.setForeground(Color.blue);
    l2.setForeground(Color.blue);
    l3.setForeground(Color.blue);
    l1.setFont(fontword);
    l2.setFont(fontword);
    l3.setFont(fontword);
    txtCard.setBounds(220,125,150,20);
   	txtPwd.setBounds(220,155,150,20);
   	txtMoney.setBounds(220,185,150,20);
   	txtCard.setFont(fontinput);
   	txtPwd.setFont(fontinput);
   	txtMoney.setFont(fontinput);
   	btConfirm.setBounds(420,300,100,30);
   	btCancel.setBounds(420,340,100,30);
   	btBack.setBounds(420,380,100,30);
   	Title.setBounds(50,20,490,100);
   	btConfirm.setFont(fontinput);
   	btCancel.setFont(fontinput);
   	btBack.setFont(fontinput);
   	Title.setForeground(Color.red);
   	Title.setFont(font);
   	this.add(Title);
   	btConfirm.addActionListener(listener);
   	btCancel.addActionListener(listener);
   	btBack.addActionListener(listener);
   	this.add(l1);
   	this.add(l2);
   	this.add(l3);
   	this.add(txtCard);
   	this.add(txtPwd);
   	this.add(txtMoney);	
   	this.add(btConfirm);
   	this.add(btCancel);
   	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("取款"))
	{
   try{
	    String title = "提示";
        int type = JOptionPane.INFORMATION_MESSAGE;
        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"));
	          UserName = new String(r.getString("Name"));
	    	}
	    	if (UserPwd.equals(String.valueOf(txtPwd.getPassword())))
	          {
	          	s.executeUpdate("UPDATE Accounts SET Sum=Sum-"+txtMoney.getText().trim()+" WHERE CardID='"+txtCard.getText().trim()+"'");
	          	JOptionPane.showMessageDialog(f, "取款操作已经完成!\n"+"姓名为: "+UserName+" 的客户成功取出"+txtMoney.getText().trim()+"元现金。", "提示:", 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);
      }
     }  
    }
    
   } 
  }
  
		
	

⌨️ 快捷键说明

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