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

📄 quarypane.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 QuaryPane 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 ResultName = new JLabel("  姓名:");
   JLabel ResultCash = new JLabel("  余额:");
   JLabel ResultID = new JLabel("身份证:");
   JLabel Title=new JLabel(new ImageIcon("..\\..\\title\\quary.gif"));
   Font font=new Font("Serif",Font.BOLD,30);
   Icon imgName=new ImageIcon(".\\gif\\name.gif");
   Icon imgID=new ImageIcon(".\\gif\\id.gif");
   Icon imgCash=new ImageIcon(".\\gif\\cash.gif");
   JLabel picName=new JLabel(imgName);
   JLabel picID=new JLabel(imgID);
   JLabel picCash=new JLabel(imgCash);
   JTextField txtCard= new JTextField(10);
   JPasswordField txtPwd= new JPasswordField(10);
   JButton btRead=new JButton("读卡");
   JButton btConfirm=new JButton("查询");
   JButton btBack=new JButton("返回");
   Icon img=new ImageIcon(".\\gif\\ts.gif");
   Component f;
   private ActionListener listener=new ActionResponse();
   public QuaryPane (Component ComponentF)
   {
   	f=ComponentF;
   	idsource = new ReadAtmID(f);
   	this.setLayout(null);
   	this.setBorder(BorderFactory.createTitledBorder(
            BorderFactory.createLineBorder(Color.BLACK,1),
            "请输入用户信息",TitledBorder.CENTER,TitledBorder.TOP));
   	l1.setBounds(150,120,50,30);
   	l2.setBounds(150,150,50,30);
   	l1.setForeground(Color.blue);
    l2.setForeground(Color.blue);
    l1.setFont(fontword);
    l2.setFont(fontword);
    txtCard.setBounds(220,125,150,20);
   	txtPwd.setBounds(220,155,150,20);
   	txtCard.setFont(fontinput);
   	txtPwd.setFont(fontinput);
    ResultName.setBounds(185,250,200,30);
    ResultCash.setBounds(185,300,200,30);
    ResultID.setBounds(185,350,200,30);
    picName.setBounds(150,250,50,30);
    picCash.setBounds(150,300,50,30);
    picID.setBounds(150,350,50,30);
    ResultName.setFont(fontword);
    ResultCash.setFont(fontword);
    ResultID.setFont(fontword);
    ResultName.setForeground(Color.blue);
    ResultCash.setForeground(Color.blue);
    ResultID.setForeground(Color.blue);
    
    btConfirm.setBounds(420,340,100,30);
   	btRead.setBounds(420,300,100,30);
   	btBack.setBounds(420,380,100,30);
   	Title.setBounds(50,20,490,100);
   	btConfirm.setFont(fontinput);
   	btRead.setFont(fontinput);
   	btBack.setFont(fontinput);
   	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(txtCard);
   	this.add(txtPwd);
   	this.add(btConfirm);
   	this.add(btRead);
   	this.add(btBack);
   	this.add(ResultName);
   	this.add(ResultCash);
   	this.add(ResultID);
   	this.add(picName);
   	this.add(picID);
   	this.add(picCash);
   }
   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 UserPwd="";
            String UserName="";
            String UserCard="";
            String UserID="";
            double Money=0;
            boolean LostFlag=true;
            boolean State=true;
            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"));
	          UserCard = new String(r.getString("CardID"));
	          Money=r.getDouble("Sum");
	          LostFlag = r.getBoolean("LostFlag");
	          State = r.getBoolean("State");
	          UserID=r.getString("Licence");
	    	}
	    	if (UserPwd.equals(String.valueOf(txtPwd.getPassword())))
	        {
	           ResultName.setText("  姓名:"+UserName);
	           ResultCash.setText("  余额:"+String.valueOf(Money)+"元");
	             ResultID.setText("身份证:"+UserID);
	        }
	        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 + -