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

📄 fecth.java

📁 ATM机具有存款、取款、查询结余、打印凭条、修改密码功能。
💻 JAVA
字号:
package atm;
import javax.swing.*;
import java.awt.*;
import com.borland.jbcl.layout.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.Font;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.sql.DriverManager;
import java.sql.Statement;
import java.sql.Connection;
import java.sql.ResultSet;
import java.util.*;
/**
 * <p>Title: </p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2008</p>
 *
 * <p>Company: </p>
 *
 * @author not attributable
 * @version 1.0
 */
public class Fecth extends JFrame{
    public static String d;
    String strSql1="";
    String strSql="";
    String database_username="";
    String database_password="";
    int ab;
    int bb;
    String yy;
    public static int m;
    int s1;
    public Fecth() {
        super();
        try {
            jbInit();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
     }
     public static void main(String[] args) {
        Fecth fec=new Fecth();

    }

    private void jbInit() throws Exception {
        jLabel1.setFont(new java.awt.Font("宋体", Font.PLAIN, 25));
        jLabel1.setForeground(Color.white);
        jLabel1.setText("本机只提供100元人民币");
        jPanel1.setLayout(xYLayout1);
        jLabel2.setFont(new java.awt.Font("宋体", Font.PLAIN, 20));
        jLabel2.setForeground(Color.white);
        jLabel2.setText("输入所要提取的钱数:");
        jButton1.setText("确定");
        jButton1.addActionListener(new Fecth_jButton1_actionAdapter(this));
        jButton2.setText("取消");
        jButton2.addActionListener(new Fecth_jButton2_actionAdapter(this));
        this.getContentPane().add(jPanel1, java.awt.BorderLayout.CENTER);
        jPanel1.add(jLabel1, new XYConstraints(68, 34, -1, -1));
        jPanel1.add(jLabel2, new XYConstraints(83, 203, -1, -1));
        jPanel1.add(jTextField1, new XYConstraints(84, 257, 180, 25));
        jPanel1.add(jButton1, new XYConstraints(78, 348, -1, -1));
        jPanel1.add(jButton2, new XYConstraints(217, 348, -1, -1));
        jPanel1.setBackground(new Color(49, 106, 183));
        this.getContentPane().add(jPanel1, java.awt.BorderLayout.CENTER);
        setSize(450,550);
      setVisible(true);

    }

    JPanel jPanel1 = new JPanel();
    JLabel jLabel1 = new JLabel();
    XYLayout xYLayout1 = new XYLayout();
    JLabel jLabel2 = new JLabel();
    JTextField jTextField1 = new JTextField();
    JButton jButton1 = new JButton();
    JButton jButton2 = new JButton();

    public void jButton1_actionPerformed(ActionEvent e) {

             ResultSet rs = null;
             String url = "jdbc:odbc:atm";
             Tbalance tt=new Tbalance();
     try {
             moneySelect();
             d = jTextField1.getText();
          if (d.equals("")){
                      JOptionPane.showMessageDialog(this,"输入为空,请重新输入!");
                  }
              String er=(new java.util.Date()).toLocaleString();
              userlogin u=new userlogin();
              System.out.print("hello");
              yy=u.s;
              Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
              Connection dbConn = DriverManager.getConnection(url,database_username, database_password);
              Statement stmt = dbConn.createStatement();
     //将取款的信息插入到交易信息表中
              strSql="insert into transinfo(transdate,cardid,transtype,transmoney)"+"values('"+er+"','"+yy+"','取款','"+d+"')";
              s1=Integer.parseInt(d);
              bb=tt.aa;
              ab=bb-s1;
          if (s1%100!=0){
               JOptionPane.showMessageDialog(this,"本机只提供100元的整数倍!");
               jTextField1.setText("") ;
           }
          if(ab<0){
               JOptionPane.showMessageDialog(this,"余额不足!");
               jTextField1.setText("") ;
           }
          if(!(d.equals(""))&&!(s1%100!=0)&&!(ab<0)){
              stmt.executeUpdate(strSql);
              JOptionPane.showMessageDialog(this, "取款成功,交易金额为'"+d+"'元");
              jTextField1.setText("");
              balance1();

              moneyUpdate();
          }
      }catch(Exception ee){
              System.out.println(ee.getMessage());
       }
    }
    //刷新取款后银行卡内的钱数
public void balance1(){
        try{
          String url = "jdbc:odbc:atm";
          Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
          ResultSet rs = null;
          Connection dbConn = DriverManager.getConnection(url,database_username, database_password);
          Statement stmt = dbConn.createStatement();
          strSql1="update cardinfo set balance='"+ab+"' where cardid='"+yy+"'";
          int ee= stmt.executeUpdate(strSql1);
        }catch(Exception ex){
            ex.getMessage();
        }
}
    //提取提款机内的总钱数
    public void moneySelect(){
        try{
        String url = "jdbc:odbc:atm";
        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        ResultSet rs = null;
        Connection dbConn = DriverManager.getConnection(url,database_username, database_password);
        Statement stmt = dbConn.createStatement();
        strSql1="select * from atmMoney where id='1'";
        rs= stmt.executeQuery(strSql1);
        while(rs.next()){
            m = Integer.parseInt(rs.getString(2));
        }
       }catch(Exception ex){
           ex.getMessage();
       }
    }
    //刷新提款后提款机内的钱数
   public void moneyUpdate(){
        try{
         String url = "jdbc:odbc:atm";
         Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
         ResultSet rs = null;
         Connection dbConn = DriverManager.getConnection(url,database_username, database_password);
         Statement stmt = dbConn.createStatement();
         int m1=m-s1;
         strSql1="update atmMoney set money='"+m1+"' where id='1'";
         int ee= stmt.executeUpdate(strSql1);
          rs.close();
          stmt.close();
          dbConn.close();
       }catch(Exception ex){
            ex.getMessage();
        }
   }
    public void jButton2_actionPerformed(ActionEvent e) {
           setVisible(false);
           Function f=new Function();
     }
    }
class Fecth_jButton2_actionAdapter implements ActionListener {
    private Fecth adaptee;
    Fecth_jButton2_actionAdapter(Fecth adaptee) {
        this.adaptee = adaptee;
    }

    public void actionPerformed(ActionEvent e) {
        adaptee.jButton2_actionPerformed(e);
    }
}

class Fecth_jButton1_actionAdapter implements ActionListener {
    private Fecth adaptee;
    Fecth_jButton1_actionAdapter(Fecth adaptee) {
        this.adaptee = adaptee;
    }

    public void actionPerformed(ActionEvent e) {
        adaptee.jButton1_actionPerformed(e);
    }

}

⌨️ 快捷键说明

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