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

📄 jdbc.java

📁 ATM系统的演示版.提供ATM系统的大部分功能.因为是演示版,尚未加入安全通讯的代码.不能直接用作商业应用.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*
 * @(#)JDBC.java 06/10/29
 *
 * Author:zjw
 *
 * v1.4
 */


import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.net.URL;
import java.sql.*;


public class JDBC extends WindowAdapter
{
	JFrame win1;
	MenuBar myMenu;
	Menu fileMenu;
	Menu helpMenu;
	MenuItem fileMenuItem1;
	MenuItem helpMenuItem1;
	MenuItem helpMenuItem2;
	MenuItem helpMenuItem3;
	MyDialog dialog1;
	TextField CardNumTxt;
	TextField PasswdTxt;
	Panel myP=new Panel();
	Panel myP2=new Panel();
	Panel myp3=new Panel();
	//Panel myP3=new Panel();
	Label logo;
	Button LoginBTN;
	Button ClearBTN;
	JButton ReturnBTN;
	JButton RemainBTN;
	JButton InfoviewBTN;
	JButton GetfeeBTN;
	JButton ChangePasswdBTN;
	JButton ExitBTN;
	String CardNum;


	int password;
	boolean flag=false;


	String url="jdbc:odbc:credit";

	JDBC()
	{
		win1=new JFrame("ATM系统v1.4版");
		win1.setLayout(new BorderLayout());

		//设置菜单
		myMenu=new MenuBar();
		fileMenu=new Menu("文件");
		helpMenu=new Menu("帮助");
		myMenu.add(fileMenu);
		myMenu.add(helpMenu);
		fileMenuItem1=new MenuItem("退出");
		helpMenuItem1=new MenuItem("关于");
		helpMenuItem2=new MenuItem("帮助主题");
		helpMenuItem3=new MenuItem("意见反馈");
		myMenu.add(fileMenu);
		myMenu.add(helpMenu);
		fileMenu.add(fileMenuItem1);
		helpMenu.add(helpMenuItem1);
		helpMenu.add(helpMenuItem2);
		helpMenu.add(helpMenuItem3);
		fileMenuItem1.addActionListener(new ActionListener1());
		helpMenuItem1.addActionListener(new ActionListener1());
		win1.setMenuBar(myMenu);


		//设置对话框(help菜单)
		dialog1=new MyDialog(win1,"关于ATM系统v1.4版",true);
		dialog1.addWindowListener(this);

		//用户名及密码
		CardNumTxt=new TextField(10);
		PasswdTxt=new TextField(10);
		PasswdTxt.setEchoChar('*');

		//设置各个Button
		win1.add(myP,BorderLayout.CENTER);
		myP.setLayout(new FlowLayout());

		//myP.add(new Label("请输入卡号:"));
		JLabel lbkh= new JLabel("请输入卡号:");
		lbkh.setFont(new Font("宋体",Font.BOLD,13));
		lbkh.setBackground(Color.blue);
		lbkh.setBorder(BorderFactory.createEtchedBorder());
		//lbkh.getIcon();
		myP.add(lbkh);
		myP.add(CardNumTxt);
		JLabel lbkh2= new JLabel("请输入密码:");
		lbkh2.setFont(new Font("宋体",Font.BOLD,13));
		lbkh2.setBackground(Color.blue);
		lbkh2.setBorder(BorderFactory.createEtchedBorder());
		//myP.add(new Label("密码:"));
		myP.add(lbkh2);
		myP.add(PasswdTxt);
		LoginBTN=new Button("登陆");
		ClearBTN=new Button("清除");
		LoginBTN.addActionListener(new ActionListener1());
		ClearBTN.addActionListener(new ActionListener1());




		RemainBTN=new JButton("账户余额");
		RemainBTN.setForeground(Color.black);
		RemainBTN.setBackground(Color.WHITE);
		RemainBTN.addActionListener(new ActionListener1());

		InfoviewBTN=new JButton("用户信息");
		InfoviewBTN.setForeground(Color.black);
		InfoviewBTN.setBackground(Color.WHITE);
		InfoviewBTN.addActionListener(new ActionListener1());

		GetfeeBTN=new JButton("取款");
		GetfeeBTN.setForeground(Color.black);
		GetfeeBTN.setBackground(Color.WHITE);
		GetfeeBTN.addActionListener(new ActionListener1());


		ChangePasswdBTN=new JButton("修改密码");
		ChangePasswdBTN.setForeground(Color.black);
		ChangePasswdBTN.setBackground(Color.WHITE);
		ChangePasswdBTN.addActionListener(new ActionListener1());

		ExitBTN=new JButton("退卡");
		ExitBTN.setForeground(Color.black);
		ExitBTN.setBackground(Color.WHITE);
		ExitBTN.addActionListener(new ActionListener1());



		myP.add(LoginBTN);
		myP.add(ClearBTN);

		win1.add(myP2,BorderLayout.EAST);
		myP2.setLayout(new GridLayout(5,1));
		myP2.add(RemainBTN);
		myP2.add(InfoviewBTN);
		myP2.add(GetfeeBTN);
		myP2.add(ChangePasswdBTN);
		myP2.add(ExitBTN);






		logo=new Label("      欢迎使用一卡通系统");

		logo.setFont(new Font("微软雅黑",Font.BOLD,20));
		logo.setForeground(Color.yellow);
		logo.setBackground(Color.ORANGE);




		win1.add(logo,BorderLayout.NORTH);
		win1.setSize(320,500);
		win1.setVisible(true);
		win1.addWindowListener(this);


	}




	public static void main(String args[])
	{



		new JDBC();
		//显示logo图片
		Thread thread;
		Logo lg=new Logo("LOGO.jpg");
		thread=new Thread(lg);
		thread.start();
	}

	//窗口关闭
	public void windowClosing(WindowEvent e)
	{
		if(e.getSource()==win1)
		{
			System.exit(0);
		}
		if(e.getSource()==dialog1)
		{
			dialog1.dispose();
		}

	}
	//登陆
	public void login(String name,int pword)
	{
		try
		{
			Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
			Connection con=DriverManager.getConnection(url);
			CallableStatement cs=con.prepareCall("{call query1(?)}");
			cs.setString(1,name);
			ResultSet rs=cs.executeQuery();


			while(rs.next())
			{

				long i=rs.getLong("password");
				//int balance=rs.getInt("Remains");
				//System.out.println(Remains);
				if(pword==i)
				{
					flag=true;
					myP.removeAll();
					Label login=new Label("登陆成功,右方的按钮已激活");
					login.setBackground(Color.YELLOW);
					myP.add(login);
					win1.setVisible(true);
				}
				/*else if(rs.isAfterLast()){

					myP.removeAll();
					Label cnerror=new Label("用户名错误");
					cnerror.setBackground(Color.YELLOW);

					win1.add(myP,BorderLayout.CENTER);
					myP.add(cnerror);
					myP.add(ReturnBTN);

				} */

				else

				{
					myP.removeAll();

					Label pwerror=new Label("密码错误");
					pwerror.setBackground(Color.YELLOW);

					myP.add(pwerror);

					win1.setVisible(true);



				}




			}

			cs.close();
			con.close();

		}
		catch(SQLException e)
		{
			System.out.println("SQLException caught");
		}
		catch(ClassNotFoundException ex)
		{
			System.out.println("error");
		}
	}

	public void balance()
	{
		try
		{
			Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
			Connection con=DriverManager.getConnection(url);
			CallableStatement cs=con.prepareCall("{call query1(?)}");
			cs.setString(1,CardNum);

			ResultSet rs=cs.executeQuery();
			while(rs.next())
			{
				int Remains=rs.getInt("Remains");
				int Cq=rs.getInt("CreditQuant");
				int Qksk =(int)(0.7*Cq+Remains);
				//System.out.println(Remains);

				myP.removeAll();
				JLabel account=new JLabel("您的余额为:  ");
				account.setFont(new Font("宋体",Font.BOLD,14));
				TextField tx3=new TextField(15);
				tx3.setText(""+Remains);
				myP.add(account);
				myP.add(tx3);
				win1.setVisible(true);
				JLabel account2=new JLabel("可用信用额度:");
				account2.setFont(new Font("宋体",Font.BOLD,14));
				TextField tx4=new TextField(15);
				tx4.setText(""+Cq);
				myP.add(account2);
				myP.add(tx4);
				win1.setVisible(true);
				JLabel account3=new JLabel("本次取款上限:");
				account3.setFont(new Font("宋体",Font.BOLD,14));
				TextField tx5=new TextField(15);
				tx5.setText(""+Qksk);
				myP.add(account3);
				myP.add(tx5);
				win1.setVisible(true);

			}

			cs.close();
			con.close();

		}
		catch(SQLException e)
		{
			System.out.println("SQLException caught");
		}
		catch(ClassNotFoundException ex)
		{
			System.out.println("error");
		}


	}
	public void Infoview(){


		try
		{
			Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
			Connection con=DriverManager.getConnection(url);
			CallableStatement cs=con.prepareCall("{call query6(?)}");
			cs.setString(1,CardNum);
			ResultSet rs=cs.executeQuery();
			while(rs.next())
			{
				String UserName=rs.getString("UserName");
				long UserID=rs.getLong("UserID");
				long UserBodyID=rs.getLong("UserBodyID");
				int Gender=rs.getInt("Gender");
				int Age=rs.getInt("Age");
				String Address=rs.getString("Address");
				long FixedTele=rs.getLong("FixedTele");
				long MobilePhone=rs.getLong("MobilePhone");



				//System.out.println(Remains);

				myP.removeAll();
				JLabel Ibview=new JLabel("您的姓名:");
				Ibview.setFont(new Font("宋体",Font.BOLD,14));
				TextField tx10=new TextField(15);
				tx10.setText(""+UserName);
				myP.add(Ibview);
				myP.add(tx10);
				win1.setVisible(true);


				JLabel Ibview2=new JLabel("性别:    ");
				Ibview2.setFont(new Font("宋体",Font.BOLD,14));
				TextField tx11=new TextField(15);
				if (Gender==1){
				tx11.setText(""+"男");
				}
				else{
					tx11.setText(""+"女");}
					myP.add(Ibview2);
					myP.add(tx11);
					win1.setVisible(true);




				JLabel Ibview3=new JLabel("用户帐号:");
				Ibview3.setFont(new Font("宋体",Font.BOLD,14));
				TextField tx12=new TextField(15);
				tx12.setText(""+UserID);
				myP.add(Ibview3);
				myP.add(tx12);
				win1.setVisible(true);



				JLabel Ibview4=new JLabel("身份证:  ");
				Ibview4.setFont(new Font("宋体",Font.BOLD,14));
				TextField tx13=new TextField(15);
				tx13.setText(""+UserBodyID);
				myP.add(Ibview4);
				myP.add(tx13);
				win1.setVisible(true);

				JLabel Ibview5=new JLabel("年龄:    ");
				Ibview5.setFont(new Font("宋体",Font.BOLD,14));
				TextField tx14=new TextField(15);
				tx14.setText(""+Age);
				myP.add(Ibview5);
				myP.add(tx14);
				win1.setVisible(true);


				JLabel Ibview6=new JLabel("住址:    ");
				Ibview6.setFont(new Font("宋体",Font.BOLD,14));
				TextField tx15=new TextField(15);
				tx15.setText(""+Address);
				myP.add(Ibview6);
				myP.add(tx15);
				win1.setVisible(true);

⌨️ 快捷键说明

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