?? bank.java
字號:
import java.awt.*;
import java.sql.*;
import java.awt.event.*;
import javax.swing.JOptionPane;
class denglu extends Frame implements ActionListener
{
Connection con;
Statement sql;
ResultSet r1,r2;
TextField text1;
TextField text2;
Button enter;
Button quit;
Label number;
Label password;
Label biaoyu;
Checkbox controller;
Checkbox user;
CheckboxGroup leixing;
denglu()
{
super("用戶登錄");
setBounds(320,200,320,200);
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
leixing=new CheckboxGroup();
controller=new Checkbox("管理員",true,leixing);
user=new Checkbox("普通用戶",false,leixing);
text1=new TextField(15);
text2=new TextField(15);
text2.setEchoChar('*');
text1.setBackground(Color.pink);
text2.setBackground(Color.pink);
number=new Label("帳號",Label.CENTER);
password=new Label("密碼",Label.CENTER);
biaoyu=new Label("歡迎使用銀行卡管理系統",Label.CENTER);
enter=new Button("登錄");
quit=new Button("退出");
enter.setBackground(Color.pink);
quit.setBackground(Color.pink);
enter.addActionListener(this);
quit.addActionListener(this);
Panel p=new Panel();
p.setBackground(Color.pink);
p.setLayout(null);
p.add(biaoyu);biaoyu.setBounds(80,10,150,20);
p.add(number);number.setBounds(60,40,30,20);
p.add(text1);text1.setBounds(100,40,150,20);
p.add(password);password.setBounds(60,70,30,20);
p.add(text2);text2.setBounds(100,70,150,20);
p.add(controller);controller.setBounds(80,100,50,20);
p.add(user);user.setBounds(160,100,80,20);
p.add(enter);enter.setBounds(80,130,45,20);
p.add(quit);quit.setBounds(180,130,45,20);
add(p);
setVisible(true);
setResizable(false);
}
public void actionPerformed(ActionEvent e)
{
String s1,s2;
boolean b1=false;
if(e.getSource()==quit)
{
System.exit(0);
}
else if(e.getSource()==enter && user.getState()==true)
{
try
{
con=DriverManager.getConnection("jdbc:odbc:superman","iceman","1986925");
sql=con.createStatement();
r1=sql.executeQuery("SELECT * FROM user");
while((b1=r1.next())==true)
{
s1=r1.getString("counts");
if(s1.equals(text1.getText().trim()))
{
String i=r1.getString("report");
if(i.equals("1"))
{
s2=r1.getString("password");
if(s2.equals(text2.getText().trim()))
{
dispose();
use yonghu=new use(s1);
con.close();
}
else
{
JOptionPane.showMessageDialog(this,"對不起,密碼不正確!","提示",JOptionPane.ERROR_MESSAGE);
text2.setText(null);
con.close();
}
}
else
{
JOptionPane.showMessageDialog(this,"對不起,此帳號已經掛失!","提示",JOptionPane.ERROR_MESSAGE);
text1.setText(null);
con.close();
}
}
}
if(b1==false)
{
JOptionPane.showMessageDialog(this,"對不起,帳號不正確!","提示",JOptionPane.ERROR_MESSAGE);
text1.setText(null);
con.close();
}
}
catch(SQLException e3)
{
}
}
else if(e.getSource()==enter && controller.getState()==true)
{
try
{
con=DriverManager.getConnection("jdbc:odbc:superman","iceman","1986925");
sql=con.createStatement();
r2=sql.executeQuery("SELECT * FROM controller");
while((b1=r2.next())==true)
{
s1=r2.getString("counts");
if(s1.equals(text1.getText().trim()))
{
s2=r2.getString("password");
if(s2.equals(text2.getText().trim()))
{
dispose();
control guanli=new control();
con.close();
}
else
{
JOptionPane.showMessageDialog(this,"對不起,密碼不正確!","提示",JOptionPane.ERROR_MESSAGE);
text2.setText(null);
con.close();
}
}
}
if(b1==false)
{
JOptionPane.showMessageDialog(this,"對不起,帳號不正確!","提示",JOptionPane.ERROR_MESSAGE);
text1.setText(null);
con.close();
}
}
catch(SQLException e2)
{
}
}
}
}
class use extends Frame implements ActionListener
{
Connection con;
Statement sql;
ResultSet r;
Button quqian;Button zhuanzhang;Button gaimi;
Button chaxun;Button fanhui;Button quit;
TextField text,text1,text2,text3,text4,text5,text6,text7,text8,text9;
Button enter,cancel,button1,button2,button3,button4;
Panel p,p1,p2,p3,p4,p5;
CardLayout card;
String acount;
use(String s)
{
super("普通用戶");
setLayout(null);
setBounds(450,250,450,250);
setBackground(Color.pink);
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
dispose();
}
});
acount=s;
quqian=new Button("取錢");
zhuanzhang=new Button("轉帳");
gaimi=new Button("修改密碼");
chaxun=new Button("查詢帳戶");
fanhui=new Button("返回");
quit=new Button("退出");
quqian.addActionListener(this);
zhuanzhang.addActionListener(this);
gaimi.addActionListener(this);
chaxun.addActionListener(this);
fanhui.addActionListener(this);
quit.addActionListener(this);
p=new Panel();p1=new Panel();p2=new Panel();
p3=new Panel();p4=new Panel();p5=new Panel();
add(quqian);quqian.setBounds(15,65,60,30);
add(chaxun);chaxun.setBounds(15,120,60,30);
add(fanhui);fanhui.setBounds(15,175,60,30);
add(zhuanzhang);zhuanzhang.setBounds(375,65,60,30);
add(gaimi);gaimi.setBounds(375,120,60,30);
add(quit);quit.setBounds(375,175,60,30);
card=new CardLayout();
p.setLayout(card);
p1.add(new Label("請選擇相應的操作!",Label.CENTER));
p2.setLayout(null);
Label zhuyi=new Label("注意:取款金額必須為整數",Label.CENTER);
p2.add(zhuyi);zhuyi.setBounds(50,20,150,20);
Label jine=new Label("請輸入取款金額",Label.CENTER);
p2.add(jine);jine.setBounds(10,50,100,20);
text=new TextField(15);text.setBackground(Color.pink);
p2.add(text);text.setBounds(120,50,110,20);
enter=new Button("確定");cancel=new Button("取消");
p2.add(enter);enter.setBounds(50,100,35,20);enter.setBackground(Color.pink);
p2.add(cancel);cancel.setBounds(160,100,35,20);cancel.setBackground(Color.pink);
p3.setLayout(null);
Label name=new Label("姓名",Label.CENTER);text1=new TextField(15);
p3.add(name);name.setBounds(35,15,30,20);
p3.add(text1);text1.setBounds(75,15,140,20);text1.setBackground(Color.pink);
Label zhanghao=new Label("帳號",Label.CENTER);text2=new TextField(15);
p3.add(zhanghao);zhanghao.setBounds(35,55,30,20);
p3.add(text2);text2.setBounds(75,55,140,20);text2.setBackground(Color.pink);
Label yue=new Label("余額",Label.CENTER);text3=new TextField(15);
p3.add(yue);yue.setBounds(35,95,30,20);
p3.add(text3);text3.setBounds(75,95,140,20);text3.setBackground(Color.pink);
Label shenfen=new Label("身份證",Label.CENTER);text4=new TextField(15);
p3.add(shenfen);shenfen.setBounds(35,135,35,20);
p3.add(text4);text4.setBounds(75,135,140,20);text4.setBackground(Color.pink);
p4.setLayout(null);
Label label=new Label("注意:轉帳金額必須為整數",Label.CENTER);
p4.add(label);label.setBounds(55,20,150,20);
Label label1=new Label("請輸入對方帳號",Label.CENTER);text5=new TextField(15);
p4.add(label1);label1.setBounds(20,50,90,20);
p4.add(text5);text5.setBounds(120,50,120,20);text5.setBackground(Color.pink);
Label label2=new Label("請輸入轉帳金額",Label.CENTER);text6=new TextField(15);
p4.add(label2);label2.setBounds(20,90,90,20);
p4.add(text6);text6.setBounds(120,90,120,20);text6.setBackground(Color.pink);
button1=new Button("確定");button2=new Button("取消");
p4.add(button1);button1.setBounds(55,130,35,20);button1.setBackground(Color.pink);
p4.add(button2);button2.setBounds(165,130,35,20);button2.setBackground(Color.pink);
p5.setLayout(null);
Label label3=new Label("請輸入舊密碼",Label.CENTER);text7=new TextField(15);
p5.add(label3);label3.setBounds(20,15,90,20);
p5.add(text7);text7.setBounds(120,15,120,20);text7.setBackground(Color.pink);text7.setEchoChar('*');
Label label4=new Label("請輸入新密碼",Label.CENTER);text8=new TextField(15);
p5.add(label4);label4.setBounds(20,55,90,20);
p5.add(text8);text8.setBounds(120,55,120,20);text8.setBackground(Color.pink);text8.setEchoChar('*');
Label label5=new Label("請確認新密碼",Label.CENTER);text9=new TextField(15);
p5.add(label5);label5.setBounds(20,95,90,20);
p5.add(text9);text9.setBounds(120,95,120,20);text9.setBackground(Color.pink);text9.setEchoChar('*');
button3=new Button("確定");button4=new Button("取消");
p5.add(button3);button3.setBounds(30,135,35,20);button3.setBackground(Color.pink);
p5.add(button4);button4.setBounds(205,135,35,20);button4.setBackground(Color.pink);
enter.addActionListener(this);
cancel.addActionListener(this);
button1.addActionListener(this);
button2.addActionListener(this);
button3.addActionListener(this);
button4.addActionListener(this);
p.add("1",p1);p.add("2",p2);p.add("3",p3);p.add("4",p4);p.add("5",p5);
add(p);p.setBounds(90,50,250,200);
setVisible(true);
setResizable(false);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==quqian)
{
card.show(p,"2");
}
else if(e.getSource()==chaxun)
{
card.show(p,"3");
try
{
con=DriverManager.getConnection("jdbc:odbc:superman","iceman","1986925");
sql=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
r=sql.executeQuery("SELECT * FROM user");
while(r.next())
{
String s=r.getString("counts");
if(acount.equals(s))
{
text1.setText(r.getString("name"));text1.setEditable(false);
text2.setText(s);text2.setEditable(false);
text3.setText(r.getString("deposit"));text3.setEditable(false);
text4.setText(r.getString("number"));text4.setEditable(false);
break;
}
}
con.close();
}
catch(SQLException ee)
{
}
}
else if(e.getSource()==zhuanzhang)
{
card.show(p,"4");
}
else if(e.getSource()==gaimi)
{
card.show(p,"5");
}
else if(e.getSource()==fanhui)
{
dispose();
denglu redenglu=new denglu();
}
else if(e.getSource()==quit)
{
dispose();
}
else if(e.getSource()==enter)
{
if(text.getText().trim().equals(""))
{
JOptionPane.showMessageDialog(this,"請輸入取款金額!","提示",JOptionPane.ERROR_MESSAGE);
}
else if(Float.valueOf(text.getText().trim()).floatValue()<1.0)
{
JOptionPane.showMessageDialog(this,"取款金額必須大于1!","提示",JOptionPane.ERROR_MESSAGE);
}
else
{
try
{
con=DriverManager.getConnection("jdbc:odbc:superman","iceman","1986925");
sql=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
r=sql.executeQuery("SELECT * FROM user");
while(r.next())
{
if(acount.equals(r.getString("counts")))
{
break;
}
}
long a=r.getLong("deposit");
if(a<Long.parseLong(text.getText().trim()))
{
JOptionPane.showMessageDialog(this,"對不起,余額不足!","提示",JOptionPane.ERROR_MESSAGE);
con.close();
}
else if(a==Long.parseLong(text.getText().trim()))
{
JOptionPane.showMessageDialog(this,"余額不能為零,最小為1,若要全部取出,請辦理消戶業務!","提示",JOptionPane.WARNING_MESSAGE);
con.close();
}
else
{
a=a-Long.parseLong(text.getText().trim());
String s="'"+acount+"'";
sql.executeUpdate("UPDATE user SET deposit="+a+" WHERE counts="+s);
JOptionPane.showMessageDialog(this,"交易成功,謝謝使用!","消息",JOptionPane.INFORMATION_MESSAGE);
text.setText(null);
con.close();
}
}
catch(SQLException e1)
{
}
}
}
else if(e.getSource()==cancel)
{
text.setText(null);
card.show(p,"1");
}
else if(e.getSource()==button1)
{
try
{
con=DriverManager.getConnection("jdbc:odbc:superman","iceman","1986925");
sql=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
r=sql.executeQuery("SELECT * FROM user");
while(r.next())
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -