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

📄 atm8.java

📁 银行自动取款机的JAVA源代码,数据库为MYSQL
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
 import javax.swing.*;
 import java.awt.*;
 import java.sql.*;
 import java.net.*;
 import java.sql.SQLException;
 import java.awt.event.*;
 class Uframe extends JFrame implements ActionListener
 { 
    int i=0;String A;int B;int chaxun=0; Connection Con=null;Statement Stmt=null; //数据库的初始化
    JLabel l0,l,l1,l2,l3,l4,l5,l6,l7,l8,l9,a1,a2,a3,a4,a5,a6;   //面版和标签的定义
    JButton A0,A1,A2,A3,b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13,b14,b15;
    JPanel p,p00,p0,p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12,p13;JPanel p14,p15,p16,p17,p18;
    Container c;CardLayout cq;
    JTextField t1,t2,t3,t4,t6,f1,f3,f6,f7,f8;JPasswordField myPassword;JPasswordField myPassword2;//文本框的定义
   JPasswordField myPassword3;JPasswordField myPassword4;JTextArea D1;
   
   Manager mana=new  Manager();
   Chuhu h=new Chuhu();//储户对象的调用
   public int f()
   {int b=Integer.parseInt(f1.getText());
   return b;
   }
   public Uframe()
   {
     super("欢迎使用中国私人银行ATM自动取款机!"); 
     c=getContentPane();
     cq=new CardLayout(); //卡片布局的设置
     setSize(400,200);
     c.setLayout(cq);
    c.setBackground(Color.green); //背景颜色的设置
    try{Class.forName("com.mysql.jdbc.Driver");} //加载驱动程序
   catch(ClassNotFoundException e){}
  try{
  Con=DriverManager.getConnection("jdbc:mysql://localhost/mydate?user=root&password=831027");//建立连接时应捕获SQLException异常
    Stmt=Con.createStatement();
  }
  catch(SQLException ee) {}
    p00=new JPanel();A0=new JButton("点击进入");p18=new JPanel(); //主界面的定义
      p00.setLayout(new BorderLayout());p00.setBackground(Color.CYAN);
    Color n=new Color(245,12,73);A0.setForeground(n);p18.add(A0);
   Color n5=new Color(245,4,27);
    l0=new JLabel("想要钱吗?来取吧!");Font m1=new Font("Helvetica",Font.PLAIN,60);//字体的设置
     Color q=new Color(193,33,211);l0.setFont(m1);
     l0.setForeground(q);p00.add(l0,BorderLayout.CENTER);
     p18.setBackground(Color.CYAN); p00.add(p18,BorderLayout.SOUTH);
     p=new JPanel(); p0=new JPanel();p0.setBackground(Color.CYAN);
     p0.setLayout(new GridLayout(6,1));
     p.setLayout(new BorderLayout());
     p.setBackground(Color.BLUE);
     l=new JLabel("请输入登陆的帐号和密码;");
     Font m2=new Font("Courier",Font.PLAIN,18);
     l.setFont(m2);
     l.setForeground(Color.CYAN);
    JLabel l1=new JLabel("帐号");
     Color n1=new Color(12,245,12);
     Font m3=new Font("Courier",Font.PLAIN,12);
    l1.setFont(m3);
    l1.setForeground(n1);
    JPanel p1=new JPanel(); p1.setBackground(Color.BLUE); 
    f1=new JTextField(5);f1.setBackground(Color.CYAN);
    p1.add(l1);
     p1.add(f1);
    p.add(l,BorderLayout.NORTH); 
    JLabel l2=new JLabel("密码");
     Font m4=new Font("Courier",Font.PLAIN,12);
    l2.setFont(m4);
    l2.setForeground(n1);
    JPanel p2=new JPanel(); p2.setBackground(Color.BLUE);  
    myPassword=new JPasswordField(5);myPassword.setBackground(Color.CYAN);
     p2.add(l2);
     p2.add(myPassword);
     JPanel p3=new JPanel();p3.setBackground(Color.BLUE); 
     p3.setLayout(new BorderLayout());
     p3.add(p1,BorderLayout.NORTH);
      p3.add(p2,BorderLayout.CENTER);
     p.add(p3,BorderLayout.CENTER);
     JButton A1=new JButton("注册");A1.setBackground(Color.CYAN);
   JButton A2=new JButton("登陆");A2.setBackground(Color.CYAN);
    JButton A3=new JButton("退出");A3.setBackground(Color.CYAN);
    JPanel pp=new JPanel();pp.setBackground(Color.BLUE); 
    pp.add(A1);pp.add(A2);pp.add(A3);
    p.add(pp,BorderLayout.SOUTH);
     c=getContentPane();
     cq=new CardLayout();
    c.setLayout(cq);
    c.add(p00,"zero");
    c.add(p,"one");
    l1=new JLabel("姓名");//注册界面的定义
   l2=new JLabel("性别");
  l3=new JLabel("身份正号");
   l4=new JLabel("帐号");
   l5=new JLabel("密码");
   l6=new JLabel("金额");
   t1=new JTextField(25);t1.setBackground(Color.CYAN);
   t2=new JTextField(25);t2.setBackground(Color.CYAN);
   t3=new JTextField(25);t3.setBackground(Color.CYAN);
   t4=new JTextField(25);t4.setBackground(Color.CYAN);pack();
   myPassword4=new JPasswordField(6);myPassword4.setBackground(Color.CYAN);
   t6=new JTextField(24);t6.setBackground(Color.CYAN);
   b1=new JButton("提交");b1.setBackground(Color.YELLOW);
   b2=new JButton("返回");b2.setBackground(Color.YELLOW);
   b12=new JButton("退回");b12.setBackground(Color.YELLOW);
  JPanel l=new JPanel();l.setBackground(Color.CYAN);
  p0.add(l1);p0.add(t1);
   p0.add(l2);p0.add(t2);
   p0.add(l3);p0.add(t3);
   p0.add(l4);p0.add(t4);
   p0.add(l5);p0.add(myPassword4);
    p0.add(l6);p0.add(t6);l.add(p0);
   JPanel ll=new JPanel();ll.setBackground(Color.BLUE);
   ll.add(b1);ll.add(b2);
   p1=new JPanel();p1.setBackground(Color.CYAN);
   p1.setLayout(new BorderLayout());
   p1.add(l,BorderLayout.NORTH);
   p1.add(ll,BorderLayout.SOUTH);
   c.add(p1,"two");
    b14=new JButton("储户查询");//功能界面的定义
    b3=new JButton("取款");
     b4=new JButton("余额查询");
     b5=new JButton("修改密码");
     b7=new JButton("继续服务");
      b10=new JButton("转帐");
     b13=new JButton("返回"); 
  Color n3=new Color(12,245,12);
     Font m11=new Font("Courier",Font.PLAIN,18);
    b14.setFont(m11);
    b14.setForeground(n3);
  Font m12=new Font("Courier",Font.PLAIN,18);
    b5.setFont(m12);
    b5.setForeground(n3);
   Font m5=new Font("Courier",Font.PLAIN,18);
    b3.setFont(m5);
    b3.setForeground(n3);
    Font m6=new Font("Courier",Font.PLAIN,18);b4.setFont(m6);
    b4.setForeground(n3);
   Font m7=new Font("Courier",Font.PLAIN,18);b4.setFont(m7);
    b4.setForeground(n3);
   Font m8=new Font("Courier",Font.PLAIN,18);b7.setFont(m8);
    b7.setForeground(n3);Font m9=new Font("Courier",Font.PLAIN,18);
    b10.setFont(m9);
    b10.setForeground(n3);
   Font m10=new Font("Courier",Font.PLAIN,18);b13.setFont(m10);
    b13.setForeground(n3);
   b10.setBackground(Color.BLUE); b13.setBackground(Color.BLUE); b7.setBackground(Color.BLUE);
      b4.setBackground(Color.BLUE); b3.setBackground(Color.BLUE); b5.setBackground(Color.BLUE);   
        b14.setBackground(Color.BLUE); 
       p12=new JPanel();
      p2=new JPanel();p7=new JPanel();p8=new JPanel();
     p2.setBackground(Color.PINK);  p12.setBackground(Color.PINK);  
     p8.setLayout(new GridLayout(3,1));
     p12.setLayout(new GridLayout(1,1));
     p2.setLayout(new BorderLayout(5,5));
     p7.setLayout(new GridLayout(3,1));
     p7.add(b3);p7.add(b4);p12.add(b14);
     p7.add(b5);p8.add(b7);p8.add(b10);p8.add(b13);
    p2.add(p7,BorderLayout.EAST);p2.add(p8,BorderLayout.WEST);
    p2.add(p12,BorderLayout.CENTER);
     c.add(p2,"3"); 
    l7=new JLabel("本机只能提供50和100面额的钞票,且一次最多只能取10000元");
    l8=new JLabel("请输入取款数:");
 Font m19=new Font("Courier",Font.PLAIN,50);
    l7.setFont(m19);
    l7.setForeground(n5);
 Font m20=new Font("Courier",Font.PLAIN,36);
    l8.setFont(m20);
    l8.setForeground(n5);  
    f3=new JTextField(5);f3.setBackground(Color.CYAN);
    b6=new JButton("输入");b6.setBackground(Color.YELLOW);
    JPanel a=new JPanel(); a.setBackground(Color.CYAN); 
   a.add(l8);
   a.add(f3);
    p3=new JPanel(); p9=new JPanel();p9.setBackground(Color.CYAN);
     p9.add(b6); p9.add(b12);
    p3.setLayout(new BorderLayout()); p3.setBackground(Color.CYAN); 
   p3.add(l7,BorderLayout.NORTH);
   p3.add(a,BorderLayout.CENTER);
   p3.add(p9,BorderLayout.SOUTH);
   c.add(p3,"4");
   l9=new JLabel("您的余额为:");
  Font m21=new Font("Courier",Font.PLAIN,36);
    l9.setFont(m21);
    l9.setForeground(n5); 
   b8=new JButton("确定"); b8.setBackground(Color.CYAN); 
    p4=new JPanel();p17=new JPanel(); p4.setBackground(Color.PINK); 
    p4.setLayout(new BorderLayout());p17.add(b8);p17.setBackground(Color.BLUE);
   p4.add(l9,BorderLayout.CENTER);
   p4.add(p17,BorderLayout.SOUTH);
   c.add(p4,"5");
  a1=new JLabel("输入您的新密码:"); //密码修改
  Font m14=new Font("Courier",Font.PLAIN,18);a1.setFont(m14);
    a1.setForeground(n5);
   myPassword2=new JPasswordField(5);myPassword2.setBackground(Color.CYAN);
  a2=new JLabel("重新输入您的新密码:");
 Font m15=new Font("Courier",Font.PLAIN,18);a2.setFont(m15);
    a2.setForeground(n5); 
  myPassword3=new JPasswordField(5);myPassword3.setBackground(Color.CYAN);
  a3=new JLabel("输入您的原密码:");
   Font m16=new Font("Courier",Font.PLAIN,18);a3.setFont(m16);
    a3.setForeground(n5);
  f6=new JTextField(9); p11=new JPanel();p11.setBackground(Color.CYAN);f6.setBackground(Color.CYAN);
  b9=new JButton("确定"); b9.setBackground(Color.GREEN);  
  p5=new JPanel();JPanel C32=new JPanel();p5.setBackground(Color.CYAN); 
  JPanel C33=new JPanel();C33.setBackground(Color.CYAN);
  JPanel C35=new JPanel();C33.setBackground(Color.CYAN); 
  JPanel C36=new JPanel();C33.setBackground(Color.CYAN);
  C32.setBackground(Color.CYAN);C35.setBackground(Color.CYAN);
  C36.setBackground(Color.CYAN); p11.add(b9);
  p5.setLayout(new BorderLayout());
  p5.add(C32,BorderLayout.NORTH);
  p5.add(C33,BorderLayout.CENTER);
  p5.add(p11,BorderLayout.SOUTH);
  C33.setLayout(new BorderLayout());
  C33.add(C35,BorderLayout.NORTH);
  C33.add(C36,BorderLayout.SOUTH);
  C32.add(a1);
  C32.add(myPassword2);
  C35.add(a2);
  C35.add(myPassword3);
  C36.add(a3);
  C36.add(f6);
  c.add(p5,"6");
  a4=new JLabel("转帐金额");
   a5=new JLabel("转帐卡号");
 Font m18=new Font("Courier",Font.PLAIN,36);
    a4.setFont(m18);
    a4.setForeground(n5); 
 Font m17=new Font("Courier",Font.PLAIN,36);
    a5.setFont(m17);
    a5.setForeground(n5); 
   f7=new JTextField(5);f7.setBackground(Color.CYAN);
   f8=new JTextField(5);f8.setBackground(Color.CYAN);
   JPanel p10=new JPanel();p10.setBackground(Color.CYAN);
   JPanel cc=new JPanel();cc.setBackground(Color.CYAN); 
  JPanel cc1=new JPanel();cc1.setBackground(Color.CYAN); 
   cc.add(a4);cc.add(f7);cc1.add(a5);cc1.add(f8);
  b11=new JButton("确定");b11.setBackground(Color.RED); 
  b11.setForeground(Color.BLUE);
   p6=new JPanel();p6.setBackground(Color.CYAN);
   p10.add(b11); 
     p6.setLayout(new BorderLayout());
   p6.add(cc,BorderLayout.NORTH);
  p6.add(cc1,BorderLayout.CENTER);
  p6.add(p10,BorderLayout.SOUTH);
  c.add(p6,"7");D1=new JTextArea(20,20);a6=new JLabel("储户信息:");
 Font m13=new Font("Courier",Font.PLAIN,36);
    a6.setFont(m13);
    a6.setForeground(n5); 
 b15=new JButton("确定");p14=new JPanel();p15=new JPanel();p16=new JPanel();p14.add(b15);p15.add(D1);p16.add(a6);
 p13=new JPanel();p13.setLayout(new BorderLayout());p13.add(p14,BorderLayout.SOUTH);p13.add(p16,BorderLayout.WEST);
  p13.add(p15,BorderLayout.CENTER);p13.setBackground(Color.CYAN);p14.setBackground(Color.CYAN);p15.setBackground(Color.CYAN);
  p16.setBackground(Color.CYAN);b15.setBackground(Color.RED);D1.setBackground(Color.YELLOW);
 c.add(p13,"8");pack();
      A0.addActionListener(this);  //各按纽加载到兼听器中
     A1.addActionListener(this);
    A2.addActionListener(this);
    A3.addActionListener(this);
     b1.addActionListener(this);
    b2.addActionListener(this);
    b3.addActionListener(this);
     b4.addActionListener(this);
    b5.addActionListener(this);
     b6.addActionListener(this);
     b7.addActionListener(this);
     b8.addActionListener(this);
     b9.addActionListener(this);
     b10.addActionListener(this);
     b11.addActionListener(this);
     b12.addActionListener(this);
     b13.addActionListener(this);
     b14.addActionListener(this);
     b15.addActionListener(this);
    this.addWindowListener(new Quit());
     setSize(600,350);
    cq.show(c,"zero");
   }
   

  public void actionPerformed(ActionEvent e)
  { if(e.getActionCommand()=="点击进入") //各按纽的响应
   {
    cq.show(c,"one");}
   if(e.getActionCommand()=="退出")
   {cq.show(c,"zero"); }
   if(e.getActionCommand()=="注册")
   { 
      cq.show(c,"two");
      f1.setText("");myPassword.setText("");} 
 if(e.getActionCommand()=="提交")
 {
 	 if(t3.getText().length()!=8)
     {JOptionPane.showMessageDialog(null,"对不起,身份正号码不合法!请输入合法的号码!");t3.setText("");}
     
  		if(t4.getText().length()<6)
   			{ JOptionPane.showMessageDialog(null,"您的卡号还未开通,请重新注册!");t4.setText("");t4.setText("");}
	   
 		if (myPassword4.getText().length()!=6)
     				{
     					JOptionPane.showMessageDialog(null, "对不起,密码为6位数,请重新输入!", 				                                                                   "Error", JOptionPane.ERROR_MESSAGE);
     					myPassword4.setText("");}

  try
   { 
  	Class.forName("com.mysql.jdbc.Driver");
   Con=DriverManager.getConnection("jdbc:mysql://localhost/mydate?user=root&password=831027");
   Stmt =Con.createStatement();
   Con.setAutoCommit(false);
  	String h1="";int n1,n2,n3;String h2="";
   int e1;
   h1=t1.getText();
   h2=t2.getText();
    n1=Integer.parseInt(t3.getText());
    n2=Integer.parseInt(t4.getText());
    n3=Integer.parseInt(myPassword4.getText());
    e1=Integer.parseInt(t6.getText());

⌨️ 快捷键说明

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