Java+Oracle自助银行系统

    

       2019.03.05更新   好久没有登录CSDN了,今天竟然发现有两位朋友在两月前问我,实在抱歉没有及时回复。由于我的电脑太渣,所以将Oracle 数据库换成了MySQL数据库,之前的源码文件找不到了,于是对下面的程序稍作了修改。现在附上java+mysql的源码文件:

链接:https://pan.baidu.com/s/1-v_PrUB87rshc_O9_fJZ2A 
提取码:nszi 

==================================以下为原文==========================================


本文的目的是通过自助银行系统掌握数据库编程技术,能正确连接数据库,能使用Java Swing实现程序的界面化,能对数据库中信息进行查询、插入、删除、修改。

 

1.在Oracle数据库中建立两张表

1-1.建立客户表 t_user,并进行相关约束

create table t_user (
	accountnumber varchar2(20) primary key,
	username varchar2(16),
	password varchar2(6),
	balance number(8,2),
	datetime date default sysdate
);

1-2.建立交易记录表 t_history
    

create table t_history (
	hid number(10)  primary key,
	accountnumber varchar2(20),
	money number(8,2),
	content varchar2(50),
	time date default sysdate
);

 

1-3.建立用户账号序列 seq_account 和交易订单序列 seq_hid

 

create sequence seq_account
start with 1001
increment by 1;
create sequence seq_hid
start with 1
increment 1;

1-4给t_history 的accountnumber 添加外键约束

alter table t_history add constraints fk_number foreign key(accountnumber) references  t_user(accountnumber);

 

2.Java程序设计

2-1.Java实现数据库的连接,以及完成对开户,取款,存款,转账,查询等功能的定义

package bank.system;
import java.sql.*;
public class BankSystem {
	public static Connection connection() throws SQLException, ClassNotFoundException{
		//1.加载驱动
		Class.forName("oracle.jdbc.driver.OracleDriver");
		//2.得到连接
		Connection conn=DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:orcl","scott","tiger1");
	      return conn;
	}
   public static String openAccount(String name,String pwd,String pwd1) throws ClassNotFoundException, SQLException{
	   Connection conn=connection();
	   //验证两次输入的密码是否相同
	   if(pwd.equals(pwd1))
	   {
		 //创建新用户
		String sql1="insert into t_user(accountnumber,username,password,balance) values(seq_account.nextval,?,?,100)";
	      PreparedStatement psmt=conn.prepareStatement(sql1);
	      psmt.setString(1, name);
	      psmt.setString(2, pwd);
	      ResultSet rs=psmt.executeQuery();
	      if(rs.next())
	      {
	    //返回新用户分配到的账号
	    	  Statement sm =conn.createStatement();
	    	  ResultSet rs1=sm.executeQuery("select accountnumber from t_user where username='"+name+"'");
	    	  while(rs1.next())
	    	  {
				String str =rs1.getString(1);
				return str;
	    	  }
	      }
	   }
	   return null;
   }
   public static String[] balanceInquiry(String num,String psw) throws ClassNotFoundException, SQLException
   {
	   //查询账户信息
	   Connection conn=connection();
	   String sql="select * from t_user where accountnumber='"+num+"' and password='"+psw+"'";
	   PreparedStatement psmt=conn.prepareStatement(sql);
	   ResultSet rs=psmt.executeQuery();
	   if(rs.next())
		{
		String[] str =new String[3];
			str[0]=rs.getString(1);//记录账号
			str[1]=rs.getString(2);//记录用户名
			str[2]=rs.getString(4);//记录余额
			return str;
			}
	return null;
   }
   public static Boolean deposite(String num,String psw,Float money) throws ClassNotFoundException, SQLException{
	   Connection conn=connection();
	   	//存款
	   String sql1="update t_user set balance=balance+? where accountnumber=? and password=?";
	      PreparedStatement psmt=conn.prepareStatement(sql1);
	      psmt.setFloat(1, money);
	      psmt.setString(2, num);
	      psmt.setString(3, psw);
	      int rs1=psmt.executeUpdate();
	     //同时将交易记录存入数据库
	     String sql2="insert into t_history(hid,accountnumber,money,content) values(seq_hid.nextval,"+num+","+money+",'存款')";
	      psmt=conn.prepareStatement(sql2);	
	      psmt.executeQuery();
	      if(rs1>0)
			{
	    	  return true;
			}
			else
			{
				return false;
			}
   }
   public static boolean withdraw(String num,String psw,float money) throws ClassNotFoundException, SQLException{
	   //取款
	   Connection conn=connection();
	   String sql1="update t_user set balance=balance-? where accountnumber=? and password=?";
	      PreparedStatement psmt=conn.prepareStatement(sql1);
	      psmt.setFloat(1, money);
	      psmt.setString(2, num);
	      psmt.setString(3, psw);
	      int rs1=psmt.executeUpdate();
	    //同时将交易记录存入数据库
	     String sql2="insert into t_history(hid,accountnumber,money,content) values(seq_hid.nextval,"+num+","+money+",'取款')";
	     psmt=conn.prepareStatement(sql2);	
	     psmt.executeQuery();
	      if(rs1>0)
			{
				return true;
			}
			else
			{
				return false;
			}
   }
   public static boolean transferAccounts(String fromNum,String psw,String toNum,float money) throws ClassNotFoundException, SQLException
   {
	   //转账
	   Connection conn=connection();
	   conn.setAutoCommit(false);//取消自动提交事务
	   String sql1="update t_user set balance=balance-"+money+" where accountnumber="+fromNum+" and password="+psw+"";
	   String sql2="update t_user set balance=balance+"+money+" where accountnumber="+toNum+"";
	   //将交易记录存入数据库
	   String sql3="insert into t_history(hid,accountnumber,money,content) values(seq_hid.nextval,"+fromNum+","+money+",'转账')";
	   PreparedStatement pstmt=conn.prepareStatement(sql1);
	   int result1=pstmt.executeUpdate();
	   pstmt=conn.prepareStatement(sql2);
	   int result2=pstmt.executeUpdate();
	   pstmt=conn.prepareStatement(sql3);	
	   pstmt.executeQuery();
	   if(result1>0&&result2>0)
		{
			
			conn.commit();//提交事务
			return true;
		}
		else
		{
			conn.rollback();//回滚事务
			return false;
			
		}
   }
   public static boolean accountBalance(String num,float money) throws ClassNotFoundException, SQLException
   {//用来判断转账和取款时是否余额不足
	   Connection conn=connection();
	   String sql="select balance from t_user where accountnumber=?";
	   PreparedStatement psmt =conn.prepareStatement(sql);
	   psmt.setString(1, num);
	   ResultSet rs = psmt.executeQuery();
	   if(rs.next()) 
	   {
		   float balance=rs.getFloat(1);
		   if(money>balance)
			   return false;
		   else	
			   return true; 
	   }
	return false;
   }
}

 

 

 

 

 

2-2.开户Swing界面的实现

package bank.system;

import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JTextPane;
import javax.swing.JTextField;
import javax.swing.JPasswordField;
import java.awt.Font;
import java.awt.SystemColor;
import java.awt.Color;

public class OpenAccount {

	private JFrame frame;
	private JTextField textField;
	private JPasswordField passwordField;
	private JPasswordField passwordField_1;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					OpenAccount window = new OpenAccount();
					window.frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the application.
	 */
	public JFrame getFrame()
	{
		return frame;
	}
	
	public OpenAccount() {
		initialize();
	}

	/**
	 * Initialize the contents of the frame.
	 */
	private void initialize() {
		frame = new JFrame();
		frame.getContentPane().setBackground(SystemColor.control);
		frame.setTitle("注册用户");
		frame.setBounds(400, 200, 450, 300);
		frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		frame.getContentPane().setLayout(null);
		
		JTextPane textPane = new JTextPane();
		textPane.setBackground(SystemColor.control);
		textPane.setFont(new Font("宋体", Font.PLAIN, 22));
		textPane.setText(" 用户名");
		textPane.setBounds(45, 42, 93, 42);
		frame.getContentPane().add(textPane);
		//添加用户名输入文本框
		textField = new JTextField();
		textField.setBounds(148, 42, 178, 42);
		frame.getContentPane().add(textField);
		textField.setColumns(10);
		//添加密码输入文本框
		passwordField = new JPasswordField();
		passwordField.setBounds(148, 94, 178, 44);
		frame.getContentPane().add(passwordField);
		//添加确认密码输入文本框
		passwordField_1 = new JPasswordField();
		passwordField_1.setBounds(148, 148, 178, 42);
		frame.getContentPane().add(passwordField_1);
		
		JTextPane textPane_1 = new JTextPane();
		textPane_1.setBackground(SystemColor.control);
		textPane_1.setFont(new Font("宋体", Font.PLAIN, 22));
		textPane_1.setForeground(new Color(0, 0, 0));
		textPane_1.setText(" 密码");
		textPane_1.setBounds(55, 94, 85, 44);
		frame.getContentPane().add(textPane_1);
		
		JTextPane textPane_2 = new JTextPane();
		textPane_2.setBackground(SystemColor.control);
		textPane_2.setFont(new Font("宋体", Font.PLAIN, 22));
		textPane_2.setText("确认密码");
		textPane_2.setBounds(33, 148, 105, 52);
		frame.getContentPane().add(textPane_2);
		
		JButton btnNewButton = new JButton("注册");
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				String name = textField.getText();
				//获取密码框中的密码并转换为字符串
				char[] password =passwordField.getPassword();
				String psw=new String(password);
				char[] password1 =passwordField_1.getPassword();
				String psw1=new String(password1);
				try {
					String str=BankSystem.openAccount(name,psw,psw1);
					if(str!=null)
					{
					JOptionPane.showMessageDialog(btnNewButton,"注册成功,您的账号为"+str);
					}
					else
						JOptionPane.showMessageDialog(btnNewButton,"错误,请重新输入!","Error", JOptionPane.ERROR_MESSAGE);
						textField.setText("");
						passwordField.setText("");
						passwordField_1.setText("");
				} catch (Exception e1) {
					e1.printStackTrace();
	
			}
			}
		});
		btnNewButton.setBounds(183, 209, 85, 42);
		frame.getContentPane().add(btnNewButton);
	}
}

 

 

运行结果如下:

 

 

2-3 查询Swing界面的实现

 

package bank.system;

import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JPasswordField;
import javax.swing.JTextPane;
import java.awt.Font;
import java.awt.SystemColor;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class Inquiry {

	private JFrame frame;
	private JPasswordField passwordField;
	private JTextField textField;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					Inquiry window = new Inquiry();
					window.frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the application.
	 */
	public JFrame getFrame()
	{
		return frame;
	}
	public Inquiry() {
		initialize();
	}

	/**
	 * Initialize the contents of the frame.
	 */
	private void initialize() {
		frame = new JFrame();
		frame.setTitle("信息查询");
		frame.setBounds(400, 200, 450, 300);
		frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		frame.getContentPane().setLayout(null);
		//添加密码输入框
		passwordField = new JPasswordField();
		passwordField.setBounds(144, 136, 204, 43);
		frame.getContentPane().add(passwordField);
		//添加账号输入文本框
		textField = new JTextField();
		textField.setBounds(144, 59, 208, 43);
		frame.getContentPane().add(textField);
		textField.setColumns(10);
		
		JTextPane textPane = new JTextPane();
		textPane.setBackground(SystemColor.control);
		textPane.setFont(new Font("宋体", Font.PLAIN, 20));
		textPane.setText("      账号");
		textPane.setBounds(23, 59, 111, 43);
		frame.getContentPane().add(textPane);
		
		JTextPane textPane_1 = new JTextPane();
		textPane_1.setBackground(SystemColor.control);
		textPane_1.setFont(new Font("宋体", Font.PLAIN, 20));
		textPane_1.setText("  密码");
		textPane_1.setBounds(59, 136, 82, 43);
		frame.getContentPane().add(textPane_1);
		
		JButton btnNewButton = new JButton("确定");
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				String num=textField.getText();
				//获取密码框中的密码并转换为字符串
				char[] password =passwordField.getPassword();
				String psw=new String(password);
				try {
					String[] str =BankSystem.balanceInquiry(num,psw);
					JOptionPane.showMessageDialog(btnNewButton, "账号:"+str[0]+"  用户名:"+str[1]+"  余额:"+str[2]);
				} catch (Exception e1) {
					// TODO Auto-generated catch block
					JOptionPane.showMessageDialog(btnNewButton,"账号未注册或密码错误!","Error", JOptionPane.ERROR_MESSAGE);
				}		
			}
		});
		btnNewButton.setBounds(172, 213, 111, 38);
		frame.getContentPane().add(btnNewButton);
	}
}

 

运行结果如下:

 

 

 

 

2-4 存款Swing界面的实现

 

package bank.system;

import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JTextPane;
import javax.swing.JTextField;
import java.awt.Font;
import java.awt.SystemColor;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.sql.SQLException;
import java.awt.event.ActionEvent;
import javax.swing.JPasswordField;

public class Deposite {

	private JFrame frame;
	private JTextField textField_1;
	private JTextField textField_2;
	private JPasswordField passwordField;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					Deposite window = new Deposite();
					window.frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the application.
	 */
	public JFrame getFrame()
	{
		return frame;
	}
	public Deposite() {
		initialize();
	}

	/**
	 * Initialize the contents of the frame.
	 */
	private void initialize() {
		frame = new JFrame();
		frame.setTitle(" 存款");
		frame.setBounds(400, 200, 450, 300);
		frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		frame.getContentPane().setLayout(null);
		
		JTextPane textPane = new JTextPane();
		textPane.setBackground(SystemColor.control);
		textPane.setFont(new Font("宋体", Font.PLAIN, 22));
		textPane.setText(" 账号");
		textPane.setBounds(37, 37, 116, 45);
		frame.getContentPane().add(textPane);
		//添加账号输入文本框
		textField_1 = new JTextField();
		textField_1.setBounds(176, 37, 186, 45);
		frame.getContentPane().add(textField_1);
		textField_1.setColumns(10);
		
		JTextPane textPane_1 = new JTextPane();
		textPane_1.setFont(new Font("宋体", Font.PLAIN, 22));
		textPane_1.setText(" 密码");
		textPane_1.setBackground(SystemColor.control);
		textPane_1.setBounds(38, 102, 115, 45);
		frame.getContentPane().add(textPane_1);
		//添加密码输入文本框
		passwordField = new JPasswordField();
		passwordField.setBounds(176, 102, 186, 45);
		frame.getContentPane().add(passwordField);
		
		JTextPane textPane_2 = new JTextPane();
		textPane_2.setBackground(SystemColor.control);
		textPane_2.setFont(new Font("宋体", Font.PLAIN, 22));
		textPane_2.setText(" 存储金额");
		textPane_2.setBounds(37, 170, 116, 45);
		frame.getContentPane().add(textPane_2);
		//添加存款金额文本框
		textField_2 = new JTextField();
		textField_2.setBounds(178, 170, 184, 45);
		frame.getContentPane().add(textField_2);
		textField_2.setColumns(10);
		
		JButton btnNewButton = new JButton("确定");
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				String num = textField_1.getText();
				//获取密码框中的密码并转换为字符串
				char[] password =passwordField.getPassword();
				String psw=new String(password);
				try {
				float money =Float.parseFloat(textField_2.getText());
				try {
					boolean b =BankSystem.deposite(num, psw, money);
					if(b==true)
					{
						JOptionPane.showMessageDialog(btnNewButton, "存储成功!");
						textField_2.setText("");
						passwordField.setText("");
						textField_1.setText("");
					}
					else
					{
						JOptionPane.showMessageDialog(btnNewButton, "密码错误,请重新输入","Error",JOptionPane.ERROR_MESSAGE);
						passwordField.setText("");
					}
				} catch (ClassNotFoundException | SQLException e2) {
					JOptionPane.showMessageDialog(btnNewButton, "您输入账号不存在,请重新输入","Error",JOptionPane.ERROR_MESSAGE);
					textField_1.setText("");
				} 
				}catch(Exception e1)
				{
					JOptionPane.showMessageDialog(btnNewButton, "输入的存款金额必须是数字!","Error",JOptionPane.ERROR_MESSAGE);
					textField_2.setText("");
				}
			
			}
		});
		btnNewButton.setBounds(131, 225, 115, 36);
		frame.getContentPane().add(btnNewButton);
		
	}

}

运行结果如下:

 


2-5 取款Swing界面的实现

package bank.system;

import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JTextPane;
import javax.swing.JTextField;
import java.awt.Font;
import java.awt.SystemColor;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JPasswordField;

public class Withdraw {

	JFrame frame;
	private JTextField textField;
	private JTextField textField_2;
	private JPasswordField passwordField;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					Withdraw window = new Withdraw();
					window.frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the application.
	 */
	public JFrame getFrame()
	{
		return frame;
	}
	public Withdraw(){
		initialize();
	}

	/**
	 * Initialize the contents of the frame.
	 */
	private void initialize() {
		frame = new JFrame();
		frame.setTitle("取 款");
		frame.setBounds(400, 200, 450, 300);
		frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		frame.getContentPane().setLayout(null);
		
		JTextPane textPane = new JTextPane();
		textPane.setBackground(SystemColor.control);
		textPane.setFont(new Font("宋体", Font.PLAIN, 22));
		textPane.setText(" 账号");
		textPane.setBounds(37, 37, 116, 45);
		frame.getContentPane().add(textPane);
		//添加账号输入文本框
		textField = new JTextField();
		textField.setBounds(176, 37, 186, 45);
		frame.getContentPane().add(textField);
		textField.setColumns(10);
		
		JTextPane textPane_1 = new JTextPane();
		textPane_1.setFont(new Font("宋体", Font.PLAIN, 22));
		textPane_1.setText(" 密码");
		textPane_1.setBackground(SystemColor.control);
		textPane_1.setBounds(38, 102, 115, 45);
		frame.getContentPane().add(textPane_1);
		//添加密码输入文本框
		passwordField = new JPasswordField();
		passwordField.setBounds(176, 102, 186, 45);
		frame.getContentPane().add(passwordField);
		
		JTextPane textPane_2 = new JTextPane();
		textPane_2.setBackground(SystemColor.control);
		textPane_2.setFont(new Font("宋体", Font.PLAIN, 22));
		textPane_2.setText(" 取款金额");
		textPane_2.setBounds(37, 170, 116, 45);
		frame.getContentPane().add(textPane_2);
		//添加取款金额输入文本框
		textField_2 = new JTextField();
		textField_2.setBounds(178, 170, 184, 45);
		frame.getContentPane().add(textField_2);
		textField_2.setColumns(10);
		
		JButton btnNewButton = new JButton("确定");
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				String num = textField.getText();
				//获取密码框中的密码并转换为字符串
				char[] password =passwordField.getPassword();
				String psw=new String(password);
				try {
				float money =Float.parseFloat(textField_2.getText());
				boolean bl=BankSystem.accountBalance(num,money);
				
					if(bl==false)
					{
						JOptionPane.showMessageDialog(btnNewButton,"您的余额不足或账户不存在");
						textField_2.setText("");
					}
					else
					{
						boolean b =BankSystem.withdraw(num,psw,money);
						if(b==true)
						{
							JOptionPane.showMessageDialog(btnNewButton, "取款成功,请收好您的现金!");
							textField_2.setText("");
							passwordField.setText("");
							textField.setText("");
						}
						else
						{
							JOptionPane.showMessageDialog(btnNewButton, "密码错误,请重新输入","Error",JOptionPane.ERROR_MESSAGE);
							passwordField.setText("");
						}
					}
		
				}catch(Exception e1)
				{
					JOptionPane.showMessageDialog(btnNewButton, "输入的取款金额必须是数字!","Error",JOptionPane.ERROR_MESSAGE);
					textField_2.setText("");
				}
			
			}
		});
		btnNewButton.setBounds(131, 225, 115, 36);
		frame.getContentPane().add(btnNewButton);
		
	}

}

 

运行结果如下:

 

 

2-6 转账Swing界面的实现

 
package bank.system;

import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JTextPane;
import javax.swing.JTextField;
import javax.swing.JPasswordField;
import java.awt.SystemColor;
import java.awt.Font;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class TransferAccounts {

	private JFrame frame;
	private JTextField textField;
	private JTextField textField_2;
	private JPasswordField passwordField;
	private JTextField textField_1;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					TransferAccounts window = new TransferAccounts();
					window.frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the application.
	 */
	public TransferAccounts() {
		initialize();
	}

	/**
	 * Initialize the contents of the frame.
	 */
	public JFrame getFrame()
	{
		return frame;
	}
	private void initialize() {
		frame = new JFrame();
		frame.setBounds(400, 200, 450, 300);
		frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		frame.getContentPane().setLayout(null);
		
		JTextPane textPane = new JTextPane();
		textPane.setFont(new Font("宋体", Font.PLAIN, 20));
		textPane.setBackground(SystemColor.control);
		textPane.setText("   账号");
		textPane.setBounds(40, 29, 103, 32);
		frame.getContentPane().add(textPane);
		//添加账号输入文本框
		textField = new JTextField();
		textField.setBounds(153, 29, 176, 32);
		frame.getContentPane().add(textField);
		textField.setColumns(10);
		
		JTextPane textPane_1 = new JTextPane();
		textPane_1.setFont(new Font("宋体", Font.PLAIN, 20));
		textPane_1.setBackground(SystemColor.control);
		textPane_1.setText("   密码");
		textPane_1.setBounds(40, 71, 103, 40);
		frame.getContentPane().add(textPane_1);
		
		JTextPane textPane_2 = new JTextPane();
		textPane_2.setBackground(SystemColor.control);
		textPane_2.setFont(new Font("宋体", Font.PLAIN, 20));
		textPane_2.setText(" 对方账号");
		textPane_2.setBounds(40, 121, 103, 40);
		frame.getContentPane().add(textPane_2);
		//添加对方账号输入文本框
		textField_2 = new JTextField();
		textField_2.setBounds(153, 121, 176, 32);
		frame.getContentPane().add(textField_2);
		textField_2.setColumns(10);
		//添加密码输入文本框
		passwordField = new JPasswordField();
		passwordField.setBounds(153, 71, 176, 32);
		frame.getContentPane().add(passwordField);
		
		JTextPane textPane_3 = new JTextPane();
		textPane_3.setFont(new Font("宋体", Font.PLAIN, 20));
		textPane_3.setBackground(SystemColor.control);
		textPane_3.setText(" 转账金额");
		textPane_3.setBounds(40, 170, 103, 40);
		frame.getContentPane().add(textPane_3);
		//添加转账金额输入文本框
		textField_1 = new JTextField();
		textField_1.setBounds(155, 170, 174, 32);
		frame.getContentPane().add(textField_1);
		textField_1.setColumns(10);
		
		JButton btnNewButton = new JButton("确 定");
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				String fromNum = textField.getText();
				//获取密码框中的密码并转换为字符串
				char[] password =passwordField.getPassword();
				String psw=new String(password);
				String toNum = textField_2.getText();
				String str_money =textField_1.getText();
				if(fromNum.equals(toNum))
				{
					JOptionPane.showMessageDialog(btnNewButton, "您不能给自己转账!","Error",JOptionPane.ERROR_MESSAGE);
					textField_2.setText("");
				}
				else
				{
					try {
						float money=Float.parseFloat(str_money);
						boolean bl=BankSystem.accountBalance(fromNum, money);
						if(bl==false)
						{
							JOptionPane.showMessageDialog(btnNewButton,"您的余额不足或账户不存在");
							textField_1.setText("");
						}
						else 
						{
							boolean b = BankSystem.transferAccounts(fromNum, psw, toNum, money);
							if(b==true)
							{
								JOptionPane.showMessageDialog(btnNewButton,"转账成功");
								//textField.setText("");
								textField_1.setText("");
								textField_2.setText("");
								//passwordField.setText("");
							}
							else
							{
								JOptionPane.showMessageDialog(btnNewButton, "密码错误或对方账号不存在,请重新输入","Error",JOptionPane.ERROR_MESSAGE);
								passwordField.setText("");
								textField_2.setText("");
							}
						}
					}catch(Exception e1)
					{
						e1.printStackTrace();
						JOptionPane.showMessageDialog(btnNewButton, "输入的转账金额必须是数字!","Error",JOptionPane.ERROR_MESSAGE);
						textField_1.setText("");
					}
				}
	  }
    });
		btnNewButton.setBounds(135, 220, 125, 31);
		frame.getContentPane().add(btnNewButton);
  }
}

运行结果如下

 


 

2-7 自助银行系统主界面的实现

    将每一个分界面都加入到主界面按钮的监视器中。

package bank.system;

import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JTextPane;
import java.awt.Color;
import java.awt.Font;
import java.awt.SystemColor;

public class BankWindow {

	private JFrame frame;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					BankWindow window = new BankWindow();
					window.frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the application.
	 */
	public BankWindow() {
		initialize();
	}

	/**
	 * Initialize the contents of the frame.
	 */
	private void initialize() {
		frame = new JFrame();
		frame.setTitle("自助银行系统");
		frame.setForeground(Color.DARK_GRAY);
		frame.getContentPane().setFont(new Font("微软雅黑", Font.BOLD, 16));
		frame.getContentPane().setForeground(new Color(0, 0, 0));
		frame.getContentPane().setBackground(SystemColor.control);
		frame.setFont(null);
		frame.setBackground(Color.GRAY);
		frame.setBounds(400, 200, 450, 300);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		JButton btnNewButton = new JButton("开    户");
		btnNewButton.setBounds(10, 83, 175, 33);
		btnNewButton.setBackground(SystemColor.control);
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				try {
					OpenAccount window = new OpenAccount();
					window.getFrame().setVisible(true);
				} catch (Exception e1) {
					e1.printStackTrace();
				}
			}
		});
		frame.getContentPane().setLayout(null);
		frame.getContentPane().add(btnNewButton);
		
		JButton btnNewButton_1 = new JButton("存    款");
		btnNewButton_1.setBounds(10, 155, 175, 33);
		btnNewButton_1.setForeground(new Color(0, 0, 0));
		btnNewButton_1.setBackground(SystemColor.control);
		btnNewButton_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				Deposite window = new Deposite();
				window.getFrame().setVisible(true);
			}
		});
		frame.getContentPane().add(btnNewButton_1);
		
		JButton button = new JButton("取    款");
		button.setBounds(10, 220, 175, 33);
		button.setBackground(SystemColor.control);
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
					Withdraw window = new Withdraw();
					window.getFrame().setVisible(true);
			}
		});
		frame.getContentPane().add(button);
		
		JButton btnNewButton_2 = new JButton("转    账");
		btnNewButton_2.setBounds(249, 157, 175, 29);
		btnNewButton_2.setBackground(SystemColor.control);
		btnNewButton_2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				TransferAccounts window =new  TransferAccounts();
				window.getFrame().setVisible(true);
			}
		});
		frame.getContentPane().add(btnNewButton_2);
		
		JButton btnNewButton_3 = new JButton("退    出");
		btnNewButton_3.setBounds(249, 222, 178, 29);
		btnNewButton_3.setBackground(SystemColor.control);
		btnNewButton_3.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				JOptionPane.showMessageDialog(btnNewButton_3, "期待您下次使用,再见");
				System.exit(0);
			}
		});
		frame.getContentPane().add(btnNewButton_3);
		
		JButton btnNewButton_4 = new JButton("查   询");
		btnNewButton_4.setBounds(249, 83, 175, 33);
		btnNewButton_4.setBackground(SystemColor.control);
		btnNewButton_4.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				try {
					Inquiry window = new Inquiry();
					window.getFrame().setVisible(true);
				} catch (Exception e1) {
					e1.printStackTrace();
				}
			}
		});
		frame.getContentPane().add(btnNewButton_4);
		
		JTextPane textPane = new JTextPane();
		textPane.setBounds(80, 20, 298, 33);
		frame.getContentPane().add(textPane);
		textPane.setFont(new Font("宋体", Font.BOLD, 14));
		textPane.setBackground(SystemColor.control);
		textPane.setText("欢迎使用自助银行系统,请选择所需服务");
		
		JTextPane textPane_1 = new JTextPane();
		textPane_1.setForeground(new Color(0, 0, 0));
		textPane_1.setBackground(SystemColor.control);
		textPane_1.setText("   请注意周边环境安全");
		textPane_1.setBounds(143, 52, 150, 21);
		frame.getContentPane().add(textPane_1);
	}
}

运行结果如下:

 

 

3.小结:目前自助银行系统客户端程序设计告一段落了,喜欢的朋友们可以自行添加修改其他功能,也可以自己做一个管理员的界面窗口。

 

 

程序设计中使用了swing界面设计的工具windowbuilder,感兴趣的朋友可以访问:https://blog.csdn.net/qq_28859405/article/details/52562131

另外还有Oracle 11g驱动的jar包

http://www.onlinedown.net/soft/1166170.htm

https://blog.csdn.net/qiannianguji01/article/details/50506158

欢迎大家对本程序中的不足提出宝贵的建议和意见。



  • 3
    点赞
  • 33
    收藏
    觉得还不错? 一键收藏
  • 15
    评论
### 回答1: Java Oracle图书管理系统是一种基于Java编程语言和Oracle数据库的软件系统,它旨在帮助图书馆或书店有效地管理和维护其图书资源。 该系统具有以下主要功能: 1. 图书信息管理:系统可以记录图书的基本信息,如书名、作者、出版社、ISBN号等,并将其保存在Oracle数据库中。管理员可以使用系统的用户界面添加、编辑和删除图书信息。 2. 图书借阅管理:系统可以实现图书的借阅和归还功能。用户可以通过系统查询图书的可借状态,并在借阅时提供借书证信息。系统会相应地更新图书的借阅状态,并记录借阅时间和归还时间。 3. 图书搜索和检索:系统提供了便捷的搜索和检索功能。用户可以根据书名、作者、出版社等关键词进行搜索,并获取相关图书的详细信息。这可以极大地方便用户找到所需图书。 4. 用户管理:系统具备用户管理功能,管理员可以添加新用户、编辑用户信息和删除用户。此外,系统还可以维护用户的借阅记录,以便管理员或用户自行查询。 5. 统计和报表分析:系统可以根据数据库中的数据生成统计和报表分析。例如,管理员可以获得每月借阅量的报表,以及图书的热门排行榜等信息,以便了解图书馆的借阅状况。 总之,Java Oracle图书管理系统是一种功能强大且易于使用的软件系统,它可以有效地管理图书资源,提供借阅管理、图书搜索和检索、用户管理以及统计分析等功能,为图书馆或书店提供了全面的信息管理解决方案。 ### 回答2: JavaOracle图书管理系统是一种使用Java编程语言和Oracle数据库的软件应用程序,旨在帮助图书馆或其他机构管理其图书馆藏和服务。它所提供的功能可以包括以下几个方面。 首先,图书管理系统可以帮助图书馆管理图书的信息。它可以记录每本图书的基本信息,如书名、作者、出版日期、ISBN编号等。同时,它还可以记录图书的库存数量和所在位置,以便图书管理员能够更方便地管理和查找图书。 其次,该系统提供借阅和归还图书的功能。利用系统,读者可以通过输入借阅卡号或扫描图书信息将图书借出或归还。系统会自动更新图书的库存数量,并记录借阅和归还的时间和日期。这些信息对于读者的借阅历史和图书的流通情况都是非常有用的。 此外,图书管理系统还可以支持图书馆的预订和预定功能。读者可以在系统中搜索和预定他们感兴趣的图书,系统会自动记录预定信息并提醒读者图书可以借阅了。这样,读者可以更好地规划自己的阅读计划。 另外,该系统还可以提供一些辅助功能,如图书馆藏的统计和报表生成。图书管理员可以通过系统生成借阅报表、图书馆藏统计等相关数据报告,帮助他们更好地了解图书馆使用情况和获取借阅趋势。 综上所述,JavaOracle图书管理系统是一种为图书馆或其他机构提供全面管理图书馆藏和服务的软件应用程序。它具有方便、高效、准确的特点,可以帮助图书馆提供更好的服务和管理图书馆藏。 ### 回答3: JavaOracle可以结合使用来开发一个图书管理系统。图书管理系统是一个用于管理图书馆的软件系统,它可以帮助图书馆管理图书的借还、归还、查询和统计等功能。 首先,我们使用Java来编写系统的前端界面。通过Java的GUI库,我们可以设计一个用户友好的界面,包括图书的搜索、借阅和归还等功能。用户可以通过输入关键词或者图书的相关信息进行检索,系统会通过与Oracle数据库的连接,从数据库中查询出符合条件的图书信息,并将其展示在界面上。用户可以选择要借阅的图书,并进行借阅操作。当图书被借出后,系统会自动减少该图书的库存量,并记录借阅者的相关信息。当图书归还时,系统会将图书的库存量增加,并更新归还日期和相关信息。 其次,我们使用Oracle数据库来存储和管理图书的相关信息。通过设计数据库的表结构,我们可以存储图书的基本信息、借阅者的信息、借阅记录和归还记录等。通过JavaOracle数据库的连接,我们可以实现数据的增删改查等功能。当用户进行借阅操作时,系统会将借阅信息储存在数据库中,当用户进行归还操作时,系统会更新归还信息。 此外,我们可以通过JavaOracle的组合,实现一些其他功能,如借阅记录的统计和图书的推荐等。通过统计借阅记录,我们可以获得图书的借阅热度和流行趋势等信息,进一步优化图书的管理策略。通过分析用户的借阅记录和阅读偏好,我们可以向用户推荐符合其兴趣的图书,提高系统的用户体验。 总之,JavaOracle的组合可以实现一个功能完善的图书管理系统,帮助图书馆对图书进行有效的管理和服务。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 15
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值