📄 bankmain.java
字号:
//package frames;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2005</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
//主类
public class BankMain
{
public static void main(String args[])
{BankServerFr bankServerFr=new BankServerFr("银行存储系统");
bankServerFr.setVisible(true);
}
}
/* ***************************************************************** */
//下面创建初始窗口
class BankServerFr extends Frame implements ActionListener
{
Button createAcc,withdrawAcc,depositAcc;
Label label1,label2;
NewAccountFr newAccFr;//新账户窗口
CheckDepositFr checkDepositFr; //检验客户关键信息窗口
CheckWithdrawFr checkWithdrawFr;
Panel panel;
public BankServerFr(String s)
{ super(s);
setLayout(new GridLayout(5,1));
createAcc=new Button("创建新账户");
withdrawAcc=new Button("取款");
depositAcc=new Button("存款");
newAccFr=new NewAccountFr("开户窗口");//开户窗口
checkDepositFr=new CheckDepositFr("存款检查"); //存款窗口
checkWithdrawFr=new CheckWithdrawFr("取款检查");//取款窗口
panel=new Panel();
label1=new Label("请选择服务种类:");
label2=new Label("注:本软件将为您的工作带来方便,如有什么疑问请参考用户文档");
//下面将组件添加到面板
add(label1);add(new Label());
panel.setLayout(new GridLayout(1,5));
panel.add(new Label());panel.add(createAcc);panel.add(depositAcc);
panel.add(withdrawAcc);panel.add(new Label());
add(panel);add(new Label());
add(label2);
//添加完毕
newAccFr.setVisible(false);
checkDepositFr.setVisible(false);
checkWithdrawFr.setVisible(false);
//为组件添加监视器
createAcc.addActionListener(this);
withdrawAcc.addActionListener(this);
depositAcc.addActionListener(this);
//为下层组件添加监视器
newAccFr.b3.addActionListener(this);
checkDepositFr.b2.addActionListener(this);
checkWithdrawFr.b2.addActionListener(this);
(checkWithdrawFr.withdrawMoneyFr.withdrawTableFr.b).addActionListener(this);
(checkDepositFr.inputDepositFr.depositTableFr.b).addActionListener(this);
addWindowListener(new WindowAdapter()//窗口添加适配器
{public void windowClosing(WindowEvent e)
{setVisible(false);System.exit(0);}
});
checkWithdrawFr.withdrawMoneyFr.withdrawTableFr.addWindowListener(new WindowAdapter()//为打印窗口添加适配器
{public void windowClosing(WindowEvent e)
{setVisible(true);}
});
checkDepositFr.inputDepositFr.depositTableFr.addWindowListener(new WindowAdapter()//为打印窗口添加适配器
{public void windowClosing(WindowEvent e)
{setVisible(true);}
});
newAccFr.inputDepositFr.depositTableFr.addWindowListener(new WindowAdapter()//为打印窗口添加适配器
{public void windowClosing(WindowEvent e)
{setVisible(true);}
});
setBounds(300,200,450,350);
setResizable(false);
}
public void actionPerformed(ActionEvent e)
{if(e.getSource()==createAcc)// 开户按钮
{setVisible(false);
newAccFr.setVisible(true);
newAccFr.CreateAccount();
}
else if(e.getSource()==depositAcc)//存款按钮
{setVisible(false);
checkDepositFr.setVisible(true);
}
else if(e.getSource()==withdrawAcc)//取款按钮
{setVisible(false);
checkWithdrawFr.setVisible(true);
}
else if(e.getSource()==newAccFr.b3) //下一 层的取消事件
{setVisible(true);
newAccFr.setVisible(false);
}
else if(e.getSource()==checkDepositFr.b2) //下一 层的取消事件
{setVisible(true);
}
else if(e.getSource()==checkWithdrawFr.b2) //下一 层的取消事件
{setVisible(true);
}
else if(e.getSource()==checkWithdrawFr.withdrawMoneyFr.withdrawTableFr.b)
//下一 层的取消事件
{setVisible(true);
}
else if(e.getSource()==checkDepositFr.inputDepositFr.depositTableFr.b)
//下一 层的取消事件
{setVisible(true);
}
else if(e.getSource()==newAccFr.inputDepositFr.depositTableFr.b)
//下一 层的取消事件
{setVisible(true);
}
}
}
/* ******************************************************************** */
//下面是开户窗口
class NewAccountFr extends Frame implements ActionListener
{ String name, address,account,password,telephone,id,conformPassword,sex,type;
final double temp=1.00;//开户必须有一元钱
RandomAccessFile file_write;
String file_name="custom.txt";
CreationFailedDlg creationFailedDlg;
AnnounceDlg announceDlg;
NumberExceptDlg numberExceptDlg;
ConPasswordDlg conPassword;
InputDepositFr inputDepositFr;
Button b1,b2,b3;
InformationPanel inPanel;
Label l_information;
Panel panel1;
NewAccountFr(String s)
{ super(s);
creationFailedDlg=new CreationFailedDlg(this,"错误",true);
announceDlg=new AnnounceDlg(this,"错误",true);
numberExceptDlg=new NumberExceptDlg(this,"错误",true);
conPassword=new ConPasswordDlg(this,"错误",true);
inputDepositFr=new InputDepositFr("新客户存款窗口");
b1=new Button("确定");
b2=new Button("重填");
b3=new Button("取消");
l_information=new Label("请填写客户信息:");
panel1=new Panel();
inPanel=new InformationPanel();
inPanel.t_startMoney.setText(String.valueOf(temp));
creationFailedDlg.setVisible(false);
announceDlg.setVisible(false);
numberExceptDlg.setVisible(false);
conPassword.setVisible(false);
inputDepositFr.setVisible(false);
panel1.add(b1);panel1.add(b2);panel1.add(b3);
add("North",l_information);add("Center",inPanel);add("South",panel1);
add("West",new Panel());add("East",new Panel());
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
inputDepositFr.b2.addActionListener(this);
setBounds(300,200,450,350);
setResizable(false);
addWindowListener(new WindowAdapter()//窗口添加适配器
{public void windowClosing(WindowEvent e)
{setVisible(false);System.exit(0);}
});
}
void CreateAccount()
{ long len=0,l_account;
String account;
//打开一个数据流
try
{file_write=new RandomAccessFile(file_name,"rw");
}
catch(FileNotFoundException e1){creationFailedDlg.setVisible(true);}
//写入数据
try
{
len=file_write.length();//获得文件长度
if(len<=0)
{inPanel.t_account.setText("95588032021083849");
}
else
{ account=file_write.readUTF();
l_account=Long.parseLong(account);
l_account=l_account+1;
account=String.valueOf(l_account);
inPanel.t_account.setText(account);
file_write.close();
}
}
catch(IOException e11){creationFailedDlg.setVisible(true);}
}
private void WriteInf()
{
boolean a,b,c,d,k,f,g;
long l_account,l_password,l_telephone,l_id,l_conformPassword;
name=inPanel.t_name.getText();
address=inPanel.t_address.getText();
account=inPanel.t_account.getText();
password=inPanel.t_password.getText();
telephone=inPanel.t_telephone.getText();
id=inPanel.t_id.getText();
conformPassword=inPanel.t_conformPassword.getText();
type=inPanel.c_type.getSelectedItem();
if(inPanel.sexpanel.c_male.getState())
{sex=inPanel.sexpanel.c_male.getLabel();
}
else if(inPanel.sexpanel.c_female.getState())
{sex=inPanel.sexpanel.c_female.getLabel();
}
a=name.equals("");
b=address.equals("");
c=account.equals("");
d=password.equals("");
k=telephone.equals("");
f=id.equals("");
g=conformPassword.equals("");
if(!(password.equals(conformPassword)))
{conPassword.setVisible(true);
}
else if(a||b||c||d||k||f||g)
{ announceDlg.setVisible(true);
}
else
{try
{
l_password=Long.parseLong(password);
l_telephone=Long.parseLong(telephone);
l_id=Long.parseLong(id);
l_conformPassword=Long.parseLong(conformPassword);
Date date=new Date();String month,date1,year;
String temp1=date.toString();
month=temp1.substring(4,7);//截取月份
date1=temp1.substring(8,10);//截取日期
year=temp1.substring(24,28);//截取年份
if(month.equals("Jan")) //将月份转化为数字字符
month="1";
else if(month.equals("Feb"))
month="2";
else if(month.equals("Mar"))
month="3";
else if(month.equals("Apr"))
month="4";
else if(month.equals("May"))
month="5";
else if(month.equals("Jun"))
month="6";
else if(month.equals("Jul"))
month="7";
else if(month.equals("Aug"))
month="8";
else if(month.equals("Sep"))
month="9";
else if(month.equals("Oct"))
month="10";
else if(month.equals("Nov"))
month="11";
else if(month.equals("Dec"))
month="12";
temp1=date1+"/"+month+"/"+year;
//打开一个数据流
try
{file_write=new RandomAccessFile(file_name,"rw");
}
catch(FileNotFoundException e1){creationFailedDlg.setVisible(true);}
//写入数据
try{
long len=file_write.length();//获得文件长度
file_write.seek(0);
file_write.writeUTF(account);
len=file_write.length();
file_write.seek(len);
file_write.writeUTF(account);file_write.writeUTF(name);
file_write.writeUTF(sex);file_write.writeUTF(password);
file_write.writeUTF(telephone);file_write.writeUTF(id);
file_write.writeUTF(address);file_write.writeUTF(type);
file_write.writeUTF(temp1);file_write.writeDouble(temp);
inputDepositFr.inputmoneyPanel.initial(name,account,type,String.valueOf(temp),temp1);
inPanel.clear();
setVisible(false);
inputDepositFr.setVisible(true);
file_write.close();
}
catch(IOException e11){creationFailedDlg.setVisible(true);}
}
catch(NumberFormatException event){numberExceptDlg.setVisible(true);}
}
}
public void actionPerformed(ActionEvent e)
{if(e.getSource()==b1) //需要进一步编写
{ WriteInf();
}
else if(e.getSource()==b2) //需要进一步编写
{inPanel.clear();
}
else if(e.getSource()==b3) //需要进一步编写
{inPanel.clear();
setVisible(false);
}
else if(e.getSource()==inputDepositFr.b2)
{setVisible(true);
}
}
}
class InformationPanel extends Panel
{ TextField t_name,t_address,t_account,t_password,t_telephone,t_id,t_conformPassword,t_startMoney;
Label l_name,l_address,l_account,l_password,
l_telephone,l_type,l_id,l_sex,l_conformPassword,l_startMoney;
Choice c_type;
SexPanel sexpanel;
InformationPanel()
{ t_name=new TextField(10);
t_address=new TextField(30);
t_account=new TextField(20);
t_password=new TextField(10);
t_conformPassword=new TextField(10);
t_telephone=new TextField(15);
t_id=new TextField(20);
t_startMoney=new TextField(20);
c_type=new Choice();
sexpanel=new SexPanel();
l_name=new Label("姓名:");
l_address=new Label("地址:");
l_account=new Label("帐号:");
l_password=new Label("密码:");
l_conformPassword=new Label("确认密码:");
l_telephone=new Label("电话号码:");
l_id=new Label("身份证号码:");
l_type=new Label("账户类型:");
l_sex=new Label("性别:");
l_startMoney=new Label("开户金额:");
t_password.setEchoChar('*');
t_conformPassword.setEchoChar('*');
c_type.add("定期存款");c_type.add("活期存款");
//下面将添加组件
setLayout(new GridLayout(10,2));
add(l_account);add(t_account);
add(l_name);add(t_name);
add(l_sex);add(sexpanel);
add(l_password);add(t_password);
add(l_conformPassword);add(t_conformPassword);
add(l_telephone);add(t_telephone);
add(l_id);add(t_id);
add(l_address);add(t_address);
add(l_type);add(c_type);
add(l_startMoney);add(t_startMoney);
t_startMoney.setEditable(false);
t_account.setEditable(false);
}
public void clear()
{t_name.setText(""); t_address.setText("");
t_password.setText("");
t_telephone.setText("");
t_id.setText(""); t_conformPassword.setText("");
sexpanel.clear(); //运行时不起作用???????
}
}
class SexPanel extends Panel
{ Checkbox c_male,c_female;
CheckboxGroup sex;
SexPanel()
{ sex=new CheckboxGroup();
c_male=new Checkbox("男",false,sex);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -