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

📄 mainfrme.java

📁 一個模仿ATM自動提款机功能的系統,
💻 JAVA
字号:
package MainFrame;
import java.awt.*;
import javax.swing.*;
import com.borland.jbcl.layout.XYLayout;
import com.borland.jbcl.layout.*;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.ResultSet;
import DataBaseManager.DataBaseManager;
import java.sql.Statement;
import java.sql.Connection;
import java.sql.DriverManager;

public class MainFrme extends JFrame {
    XYLayout xYLayout1 = new XYLayout();
    JLabel jLabel1 = new JLabel();
    JLabel jLabel2 = new JLabel();
    JLabel jLabel3 = new JLabel();
    JTextField jTextField2 = new JTextField();
    JButton jButton1 = new JButton();
    JTabbedPane jTabbedPane1 = new JTabbedPane();
    JLabel jLabel4 = new JLabel();
    JLabel jLabel5 = new JLabel();
    JTextField jTextField3 = new JTextField();
    JButton jButton2 = new JButton();
    JTabbedPane jTabbedPane2 = new JTabbedPane();
    JLabel jLabel6 = new JLabel();
    JLabel jLabel7 = new JLabel();
    JTextField jTextField4 = new JTextField();
    JLabel jLabel8 = new JLabel();
    JTextField jTextField5 = new JTextField();
    JButton jButton3 = new JButton();
    JButton jButton4 = new JButton();
    JPasswordField jPasswordField1 = new JPasswordField();
    public MainFrme() {
        try {
            jbInit();
        } catch (Exception exception) {
            exception.printStackTrace();
        }
    }

    private void jbInit() throws Exception {
        getContentPane().setLayout(xYLayout1);
        jLabel1.setFont(new java.awt.Font("华文彩云", Font.BOLD, 18));
        jLabel1.setForeground(Color.green);
        jLabel1.setText("查询操作");
        jButton1.setText("查询");
        jButton1.addActionListener(new MainFrme_jButton1_actionAdapter(this));
        xYLayout1.setWidth(471);
        xYLayout1.setHeight(383);
        jTextField2.setEditable(false);
        jLabel3.setFont(new java.awt.Font("宋体", Font.BOLD, 15));
        jLabel3.setText("余额");
        jLabel4.setFont(new java.awt.Font("华文彩云", Font.BOLD, 18));
        jLabel4.setForeground(Color.green);
        jLabel4.setText("取款操作");
        jLabel5.setFont(new java.awt.Font("宋体", Font.BOLD, 15));
        jLabel5.setText("操作金额");
        jButton2.setText("取款");
        jButton2.addActionListener(new MainFrme_jButton2_actionAdapter(this));
        jLabel6.setFont(new java.awt.Font("华文彩云", Font.BOLD, 18));
        jLabel6.setForeground(Color.green);
        jLabel6.setText("转帐操作");
        jLabel7.setFont(new java.awt.Font("宋体", Font.BOLD, 15));
        jLabel7.setText("转入帐号");
        jLabel8.setFont(new java.awt.Font("宋体", Font.BOLD, 15));
        jLabel8.setText("操作金额");
        jButton3.setText("确定");
        jButton3.addActionListener(new MainFrme_jButton3_actionAdapter(this));
        jButton4.setText("退出");
        jButton4.addActionListener(new MainFrme_jButton4_actionAdapter(this));
        this.getContentPane().add(jLabel2, new XYConstraints(9, 11, 66, 28));
        this.getContentPane().add(jLabel1, new XYConstraints(10, 51, 120, 30));
        this.getContentPane().add(jTabbedPane2,
                                  new XYConstraints(1, 220, 470, 7));

        this.getContentPane().add(jTextField2,
                                  new XYConstraints(130, 80, 150, 30));
        this.getContentPane().add(jLabel4, new XYConstraints(12, 130, 120, 29));
        this.getContentPane().add(jLabel5, new XYConstraints(30, 169, 84, 36));
        this.getContentPane().add(jButton2, new XYConstraints(360, 160, 70, 40));
        this.getContentPane().add(jButton3, new XYConstraints(360, 288, 70, 40));

        this.getContentPane().add(jTextField4,
                                  new XYConstraints(125, 275, 150, 30));
        this.getContentPane().add(jLabel8, new XYConstraints(26, 323, 79, 36));
        this.getContentPane().add(jTextField5,
                                  new XYConstraints(125, 320, 150, 30));
        this.getContentPane().add(jTabbedPane1,
                                  new XYConstraints(1, 121, 469, -1));
        this.getContentPane().add(jLabel6, new XYConstraints(14, 233, 95, 35));
        this.getContentPane().add(jLabel7, new XYConstraints(30, 278, 84, 33));
        this.getContentPane().add(jLabel3, new XYConstraints(30, 82, 84, 31));
        this.getContentPane().add(jButton4, new XYConstraints(360, 8, 70, 40));
        this.getContentPane().add(jTextField3,
                                  new XYConstraints(130, 165, 150, 36));
        this.getContentPane().add(jButton1, new XYConstraints(360, 75, 70, 40));
        this.getContentPane().add(jPasswordField1,
                                  new XYConstraints(128, 12, 152, 32));
        jLabel2.setFont(new java.awt.Font("宋体", Font.BOLD, 12));
        jLabel2.setText("用户密码");
    }

    public static void main(String[] args) {
        MainFrme m= new MainFrme();
          m.setBounds(200,200,500,500);
        m.setVisible(true);
    }

    public void jButton1_actionPerformed(ActionEvent e) {
          try {char a[]=jPasswordField1.getPassword();
              String c=new String(a);
              if(a.length==0){
                  JOptionPane.showMessageDialog(null,"沒有輸入密码!","輸入錯誤",JOptionPane.ERROR_MESSAGE);
              }else  {ResultSet rs;
                     DataBaseManager dbm=new DataBaseManager();
                     dbm.connect();
                     String sql="select * from userTable where userpassword='"+ c+"'";
                     rs=dbm.getResult(sql);
             if(rs.next()){
                   jTextField2.setText(""+rs.getDouble("usermoney"));             }
               else  JOptionPane.showMessageDialog(null,"沒有該密碼用戶");
                       jTextField2.getText();
             }
          } catch (Exception ex) {
               JOptionPane.showMessageDialog(null,"操作错误");
          }
    }

    public void jButton2_actionPerformed(ActionEvent e) {
        try { Connection con;
              Statement stmt;
              ResultSet rs1,rs2;
              char a[]=jPasswordField1.getPassword();
              String b=new String(a);
              String c=jTextField3.getText();
              float p=Float.parseFloat(c);
              if(c.equals("")){
        JOptionPane.showMessageDialog(null,"沒有輸入交易金额!","輸入錯誤",JOptionPane.ERROR_MESSAGE);}
   else if(a.length==0){
          JOptionPane.showMessageDialog(null,"沒有輸入密碼!","輸入錯誤",JOptionPane.ERROR_MESSAGE); }
      else {
          try {  Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
                 Connection conn = DriverManager.getConnection(
                                     "jdbc:microsoft:sqlserver://localhost:1433;databaseName=ATM",
                                     "sa", "");
                       Statement   Stat = conn.createStatement();
                        rs1 = Stat.executeQuery("select * from userTable where userpassword='"+b+"'");
               if(rs1.next()){
                   if(p<rs1.getFloat("usermoney")){
                   Stat.executeUpdate("update userTable set usermoney=usermoney-'"+c+"' where userpassword='"+b+"'");
                   JOptionPane.showMessageDialog(null,"您成功取了"+c);
                   jTextField3.setText("");
                   }else JOptionPane.showMessageDialog(null,"餘額不足!");}
               else {
                    JOptionPane.showMessageDialog(null,"密码错误!");
                      jTextField3.setText("");
                      jPasswordField1.setText("");
  }
      }catch (Exception ex) {
         System.out.println("数据库连接失败");
               }
    }
        } catch (Exception ex) {
             JOptionPane.showMessageDialog(null,"操作错误");
        }
    }

    public void jButton3_actionPerformed(ActionEvent e) {
   try {   char a[]=jPasswordField1.getPassword();
           String b=new String(a);
           String c=jTextField4.getText();
           String d=jTextField5.getText();
           float q=Float.parseFloat(d);
           if(a.length==0){ JOptionPane.showMessageDialog(null,"没有输入密码!","輸入錯誤",JOptionPane.ERROR_MESSAGE);}
          else{ {if(c.equals("")){
              JOptionPane.showMessageDialog(null,"沒有輸入转入ID!","輸入錯誤",JOptionPane.ERROR_MESSAGE);}
         else {if(d.equals("")){
                  JOptionPane.showMessageDialog(null,"沒有輸入操作金额!","輸入錯誤",JOptionPane.ERROR_MESSAGE);}
              else { Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
                       Connection conn = DriverManager.getConnection(
                                         "jdbc:microsoft:sqlserver://localhost:1433;databaseName=ATM",
                                         "sa", "");
                          Statement   Stat = conn.createStatement();
                          ResultSet  rs1 = Stat.executeQuery("select * from userTable where userpassword='"+ b+"'");
                          if(rs1.next()){

                         if(q<rs1.getFloat("usermoney")){
                         Stat.executeUpdate("update userTable set usermoney=usermoney-'"+d+"' where userpassword='"+b+"'");
                          Stat.executeUpdate("update userTable set usermoney=usermoney+'"+d+"' where userpassword='"+c+"'");
                         JOptionPane.showMessageDialog(null,"操作成功");
                              jTextField4.setText("");
                               jTextField5.setText("");
                              }}

         }
         }}}
   } catch (Exception ex) {
        JOptionPane.showMessageDialog(null,"操作错误");
   }
    }

    public void jButton4_actionPerformed(ActionEvent e) {
       DengLu d=new DengLu();
       d.setBounds(200,200,400,400);
       d.setVisible(true);}
    }
class MainFrme_jButton4_actionAdapter implements ActionListener {
    private MainFrme adaptee;
    MainFrme_jButton4_actionAdapter(MainFrme adaptee) {
        this.adaptee = adaptee;
    }

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


class MainFrme_jButton3_actionAdapter implements ActionListener {
    private MainFrme adaptee;
    MainFrme_jButton3_actionAdapter(MainFrme adaptee) {
        this.adaptee = adaptee;
    }

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


class MainFrme_jButton2_actionAdapter implements ActionListener {
    private MainFrme adaptee;
    MainFrme_jButton2_actionAdapter(MainFrme adaptee) {
        this.adaptee = adaptee;
    }

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


class MainFrme_jButton1_actionAdapter implements ActionListener {
    private MainFrme adaptee;
    MainFrme_jButton1_actionAdapter(MainFrme adaptee) {
        this.adaptee = adaptee;
    }

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

⌨️ 快捷键说明

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