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

📄 bank.java

📁 界面不错的东西
💻 JAVA
字号:
/**************************************************
* 程序文件名称:Bank.java
* 功能:光大银行系统程序主界面,实现查询等功能。
****************************************/
import java.awt.*;
import java.net.*;
import java.sql.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
import javax.swing.JOptionPane;
class DataWindow extends JFrame implements ActionListener
 {
   JFrame topFrame;
   FileDialog filedialog_save; //声明文件对话框
   JTextField input_msg;      //操作员输入信息
   JTextArea  con_msg;       //用户信息
   JButton b1,b2,b3,b4,b5,b6;   //查询,添加,删除,存钱,取钱;
   JLabel label;
   JMenuBar mbar;
   JMenu mfile,medit,mhelp;
   JMenuItem con_draw,con_save,back_data,quit,addedit,modedit,deledit,hhelp,about;
   DataWindow()
   {
      super("光大银行系统(GUANGDA BANK MANAGEMENT SYSTEM) V1.0.1.3");
      this.setBounds(240,240,600,400);
      this.setVisible(true);
      Container con=getContentPane();
 
      //con.add(new JScrollPane(con_msg));
      mbar=new JMenuBar();
      setJMenuBar(mbar);
      mbar.setOpaque(true);
      mfile=new JMenu("银行日常业务");
      medit=new JMenu("储户处理业务");
      mhelp=new JMenu("系统信息帮助");
      mbar.add(mfile);
      mbar.add(medit);
      mbar.add(mhelp);
      
      con_draw=new JMenuItem("银行储户取款");
      con_save=new JMenuItem("银行储户存钱");
      back_data=new JMenuItem("备份数据");
      quit=new JMenuItem("退出");

      addedit=new JMenuItem("储户开户");
      modedit=new JMenuItem("密码修改");
      deledit=new JMenuItem("储户注销");
      hhelp=new JMenuItem("帮助");
      about=new JMenuItem("关于......");

      mfile.add(con_draw);  mfile.add(con_save);  mfile.add(back_data);
      mfile.addSeparator(); mfile.add(quit);
     
      medit.add(addedit); medit.add(modedit); medit.add(deledit);

      mhelp.add(hhelp); mhelp.add(about);

      con_draw.addActionListener(this);
      con_save.addActionListener(this);
      quit.addActionListener(this);
      modedit.addActionListener(this);
      deledit.addActionListener(this);
      hhelp.addActionListener(this);
      about.addActionListener(this);
      addedit.addActionListener(this);
      
      input_msg=new JTextField(16);
      con_msg=new JTextArea(8,15);
      con_msg.setEditable(false);
      
      
      b1=new JButton("查询储户信息");
      b2=new JButton("储户开户");
      b3=new JButton("密码修改");
      b4=new JButton("储户注销");
      b5=new JButton("储户取款");
      b6=new JButton("储户存款");
      JPanel p1=new JPanel(),p2=new JPanel(); //添加面板
      label=new JLabel("输入储户的帐号:");
      label.setFont(new Font("隶书",20,20));
      
      p1.add(label);  p1.add(input_msg);  p1.add(b1);  
      p2.add(b2); p2.add(b3); p2.add(b4);p2.add(b5);p2.add(b6);
      con.add(p1,"North");
      con.add(p2,"South");
      con.add(new JScrollPane(con_msg),"Center");
       
      b1.addActionListener(this);
      b2.addActionListener(this);
      b3.addActionListener(this);
      b4.addActionListener(this);
      b5.addActionListener(this);
      b6.addActionListener(this);

      input_msg.addActionListener(this);
      back_data.addActionListener(this);

      //define save file dialog
      filedialog_save=new FileDialog(this,"保存文件对话框",FileDialog.SAVE);
      filedialog_save.addWindowListener(new WindowAdapter(){
           public void windowClosing(WindowEvent e)
            {
                filedialog_save.setVisible(false);
            }
         });
      addWindowListener(new WindowAdapter()
         {
           public void windowClosing(WindowEvent e)
               {
                 System.exit(0);
               }
          });
    }


       //实现按钮监听事件
   public void actionPerformed(ActionEvent e)
   {
      //如果是查询
       if(e.getSource()==b1||e.getSource()==input_msg)
          {
             con_msg.setText("");
             if(input_msg.getText().trim().equals(""))
               {
                   JOptionPane.showMessageDialog(this,"查询的对象不能为空!","警告",JOptionPane.WARNING_MESSAGE);
                }
            else{
                 try{ 
                     Query_con_msg();
                    }
                 catch(SQLException ce){}
                }
            }
       //如果是添加
     else if(e.getSource()==b2||e.getSource()==addedit)
          {
             new AddWin();   //AddWin 是添加窗口的类
          }
      //如果是修改
     else if(e.getSource()==b3||e.getSource()==modedit)
          {
             new ModifyWin();   //ModifyWin 是修改窗口的类
          }
      //如果是删除
     else if(e.getSource()==b4||e.getSource()==deledit)
          {
             new DelWin();   //DelWin 是删除窗口的类
          }
    else if(e.getSource()==con_draw||e.getSource()==b5) //储户取款
     {
      new Draw();  //取款的实现定义一个新类
     }
    else if(e.getSource()==con_save||e.getSource()==b6) //储户存款
      {
       new Save();
      }
    else if(e.getSource()==back_data) //备份
      {
        File fromfile=new File("Bankdb.mdb");
        FileInputStream fis=null;
        filedialog_save.setVisible(true);
        try{
            //建立文件流
            fis=new FileInputStream(fromfile);
            //定义变量来存储输入流中读取出来的文件
            int bytesRead;
            //定义4KB容量的buffer数组
            byte[]buf=new byte[4*1024];
            //建立新文件对象
            File tofile=new File(filedialog_save.getDirectory(),filedialog_save.getFile());
            //建立文件输出流
            FileOutputStream fos=new FileOutputStream(tofile);
            //写入新文件(备份文件)
            while((bytesRead=fis.read(buf))!=-1)
             {
              fos.write(buf,0,bytesRead);
             } 
            fos.flush();
            fos.close();
            fis.close();
        }
        catch(IOException e2){}
      }
      else if(e.getSource()==quit) //退出
      {
        System.exit(0);
      }
       //关于信息
      else if(e.getSource()==about)//关于
      {
        final String AboutMsg="CNU DEVELOPED GUANGDA BANK SYSTEM V1.0.2 BETA \n\n"+
         "Copyright(c)2007.Allright Reserved"+"\n 任仲山(POSTGRADUATE NO.2071002017 @ CNU)";
        JOptionPane.showMessageDialog(topFrame,AboutMsg);
      }
       //帮助
      else if(e.getSource()==hhelp)
      {
       new Help_Win();
      }
  }

    //实现查询功能
   public void Query_con_msg() throws SQLException
   {  
      Connection Con=null;
      Statement  Stmt=null;
      boolean boo=false;
      String temp;
      Con=DriverManager.getConnection("jdbc:odbc:Bankdb","","");
      Stmt=Con.createStatement();
      ResultSet rs;
      temp=input_msg.getText().trim();
      final String ErrorMsg="你要查询的储户不存在,请查证!";
      try{
         Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
         }
      catch(java.lang.ClassNotFoundException ee)
         {
          System.out.println("For Name:"+ee.getMessage());
         }
      //建立桥接器
      try{
         //Con=DriverManager.getConnection("jdbc:odbc:Bankdb","","");
         //Stmt=Con.createStatement();
          rs=Stmt.executeQuery("select *from consumer where con_acco='"+temp+"'");
         System.out.println("select *from consumer where con_acco='"+temp+"'");
         //输出储户信息,存款及余额等。
        while(rs.next())
        {boo=true;
         con_msg.append("储户帐号: "+rs.getString("con_acco")+"\n");
         con_msg.append("储户姓名: "+rs.getString("con_name")+"\n");
         con_msg.append("开户银行: "+rs.getString("con_opna")+"\n");
         con_msg.append("开户证件: "+rs.getString("con_idfi")+"\n");
         con_msg.append("证件号码: "+rs.getString("con_idno")+"\n");
         con_msg.append("货币币种: "+rs.getString("con_kind")+"\n");
         con_msg.append("开户日期: "+rs.getString("con_opde")+"\n");
         con_msg.append("帐户余额: "+rs.getString("con_rema")+"\n");
        }
         }catch(SQLException e_5){System.out.println("Database Error!"+e_5.getMessage());} //提示数据库错误或用户不存在
      Con.close();  //关闭数据库
       if(boo==false)
          JOptionPane.showMessageDialog(topFrame,ErrorMsg);  
    } //end of query_con
 }
  
     //主程序 
  public class Bank
  {
     public static void main(String args[])
       {
          JFrame.setDefaultLookAndFeelDecorated(true);
          DataWindow window=new DataWindow();
          window.validate();
       }
  }
 

⌨️ 快捷键说明

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