📄 bankframe.java
字号:
import java.io.*;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.border.*;
import javax.swing.table.*;
//
//BankFrame.java
//
//该类表示经济状况的框架
class BankFrame extends JFrame implements ActionListener {
public BankFrame() {
setTitle("欢迎光临中央银行");
setSize(520,250);
setLocation(150,200);
setResizable(false);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
dispose();
}
});
Font f=new Font("Serif",Font.BOLD,20);
nameLabel=new JLabel("用户名:",
new ImageIcon("name.gif"),JLabel.LEFT);
nameLabel.setFont(f);
nameTextField=new JTextField(name);
nameTextField.setEditable(false);
nameTextField.setHorizontalAlignment(JTextField.CENTER);
nameTextField.setFont(f);
nameTextField.setForeground(Color.red);
nameTextField.setEditable(false);
panel1.add(nameLabel);
panel1.add(nameTextField);
numberLabel=new JLabel("你的账号:",
new ImageIcon("number.gif"),JLabel.LEFT);
numberLabel.setFont(f);
numberTextField=new JTextField(String.valueOf(number));
numberTextField.setEditable(false);
numberTextField.setHorizontalAlignment(JTextField.CENTER);
numberTextField.setFont(f);
numberTextField.setForeground(Color.red);
numberTextField.setEditable(false);
panel2.add(numberLabel);
panel2.add(numberTextField);
nowLabel=new JLabel("当前存款:",
new ImageIcon("now.gif"),JLabel.LEFT);
nowLabel.setFont(f);
nowTextField=new JTextField(String.valueOf(nowAmount));
nowTextField.setEditable(false);
nowTextField.setHorizontalAlignment(JTextField.CENTER);
nowTextField.setFont(f);
nowTextField.setForeground(Color.red);
nowTextField.setEditable(false);
panel3.add(nowLabel);
panel3.add(nowTextField);
panel123.setLayout(new GridLayout(3,1));
panel123.add(panel1);
panel123.add(panel2);
panel123.add(panel3);
newButton=new JButton("重新开户",new ImageIcon("new.gif"));
saveButton=new JButton("我想存钱",new ImageIcon("save.gif"));
takeButton=new JButton("我想取钱",new ImageIcon("take.gif"));
newButton.addActionListener(this);
saveButton.addActionListener(this);
takeButton.addActionListener(this);
newButton.setFont(f);
saveButton.setFont(f);
takeButton.setFont(f);
newButton.setForeground(new Color(60,60,0));
saveButton.setForeground(new Color(60,60,0));
takeButton.setForeground(new Color(60,60,0));
panel4.setLayout(new GridLayout(1,3));
panel4.add(newButton);
panel4.add(saveButton);
panel4.add(takeButton);
panel1234.setLayout(new BorderLayout());
panel1234.add(panel123,"Center");
panel1234.add(panel4,"South");
cancelButton=new JButton("退出",new ImageIcon("cancel.gif"));
cancelButton.setFont(f);
cancelButton.addActionListener(this);
panel5.add(cancelButton);
//布局
getContentPane().add(panel1234,"Center");
getContentPane().add(panel5,"South");
}
public void actionPerformed(ActionEvent e) {
Object source=e.getSource();
if(source==cancelButton)
dispose();
else if(source==newButton) {
String name=JOptionPane.showInputDialog
("请输入你的用户名:");
long number=Long.parseLong(JOptionPane.showInputDialog
("请输入你的账号:"));
double nowAmount=Double.parseDouble(JOptionPane.showInputDialog
("你用多少钱开户:"));
if(number>=0&&nowAmount>0) {
Bank_Record.save_BR(name,number,nowAmount);
JOptionPane.showMessageDialog(this,
"开户成功,请重新进入中央银行!!!");
}
else
JOptionPane.showMessageDialog(this,
"你的输入不正确,请重试!!!");
}
else if(source==saveButton) {
double money=Double.parseDouble(JOptionPane.showInputDialog
("这位老总,你想存多少钱:"));
if(money>0) {
Bank_Record.save_BR(name,number,nowAmount+money);
JOptionPane.showMessageDialog(this,
"钱已经存好啦,重新打开本窗口才能生效,欢迎下次再来!!!");
}
else
JOptionPane.showMessageDialog(this,
"没钱就快回去,我没时间跟你玩!!!");
}
else if(source==takeButton) {
double money=Double.parseDouble(JOptionPane.showInputDialog
("这位帅哥(靓妹),你想取多少钱:"));
if(money>0&&money<=nowAmount) {
Bank_Record.save_BR(name,number,nowAmount-money);
JOptionPane.showMessageDialog(this,
"钱拿好啦,重新打开本窗口才能生效,欢迎下次再来!!!");
}
else if(money>nowAmount)
JOptionPane.showMessageDialog(this,
"对不起,存款不够,请查查你的余额!!!");
else if(money<=0)
JOptionPane.showMessageDialog(this,
"别瞎写,我没时间跟你玩!!!");
}
}
//提取文件
Bank_Record b=Bank_Record.open_BR();
private String name=b.getName();
private long number=b.getNumber();
private double nowAmount=b.getNowAmount();
private JLabel nameLabel=null;
private JLabel numberLabel=null;
private JLabel nowLabel=null;
private JTextField nameTextField=null;
private JTextField numberTextField=null;
private JTextField nowTextField=null;
private JButton newButton=null;
private JButton saveButton=null;
private JButton takeButton=null;
private JButton cancelButton=null;
private JPanel panel1=new JPanel();
private JPanel panel2=new JPanel();
private JPanel panel3=new JPanel();
private JPanel panel123=new JPanel();
private JPanel panel4=new JPanel();
private JPanel panel1234=new JPanel();
private JPanel panel5=new JPanel();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -