package qukuanji;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.WindowConstants;
public class ATM extends JFrame
{
private JLabel jl1=new JLabel("欢迎使用ATM取款机!");
private JLabel jl2=new JLabel("请输入卡号:");
private JTextField jt1=new JTextField();
private JLabel jl3=new JLabel("请输入密码:");
private JPasswordField jp1=new JPasswordField();
private JButton jb1=new JButton("确定");
private JButton jb2=new JButton("重置");
//取款机的界面设置
public ATM()
{
Container c=getContentPane();
setTitle("ATM取款体统");
setVisible(true);
setBounds(300,300,400,300);
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
setLayout(null);
jl1.setBounds(130, 60, 200, 18);
jl2.setBounds(50, 80, 200, 18);
jt1.setBounds(120, 80, 200, 20);
jl3.setBounds(50, 120, 200, 18);
jp1.setBounds(120,120 , 200, 20);
c.add(jl1);
c.add(jl2);
c.add(jt1);
c.add(jl3);
c.add(jp1);
jb1.setBounds(120, 160, 60, 40);
c.add(jb1);
jb2.setBounds(200, 160, 60, 40);
c.add(jb2);
}
//主函数
public static void main(String args[])
{
final ATM a1=new ATM();
final File file=new File("D:/input.txt");
//通过确定按钮来进入主菜单
a1.jb1.addActionListener(new ActionListener()
{
String zhanghao=new String();
String mima=new String();
String xingming=new String();
Double cunkuan;
public void actionPerformed(ActionEvent e)
{
FileReader fr = null;
try {
fr = new FileReader(file);
}
catch (FileNotFoundException e4)
{
e4.printStackTrace();
}
final BufferedReader bfr=new BufferedReader(fr);
String t = null;
try {
t = bfr.readLine();
}
catch (IOException e3)
{
e3.printStackTrace();
}
String p=null;
while(t!=null)
{
if(t.equals(a1.jt1.getText().trim()))
{
try
{
p=bfr.readLine();
String s=String.valueOf(a1.jp1.getPassword());
/*System.out.println(p);
System.out.println(s);
System.out.println(b);
System.out.println('\n');*/
boolean b=s.equals(String.valueOf(p));
if(b)
{
zhanghao=t;
mima=p;
xingming=bfr.readLine();
cunkuan=Double.valueOf(bfr.readLine());
JOptionPane.showMessageDialog(null,"输入正确,登录成功!");
a1.jt1.setText("");
a1.jp1.setText("");
//程序执行部分
final Caidan cd1=new Caidan();
a1.setVisible(false);
cd1.setVisible(true);
cd1.jb1.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
final Qukuan qk1=new Qukuan();
cd1.setVisible(false);
qk1.setVisible(true);
//每个按钮功能细化
//取款选项中的1到6按钮是选择取款的多少
qk1.jb1.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
qk1.jt1.setText(qk1.jb1.getText());
}
});
qk1.jb2.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
qk1.jt1.setText(qk1.jb2.getText());
}
});
qk1.jb3.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
qk1.jt1.setText(qk1.jb3.getText());
}
});
qk1.jb4.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
qk1.jt1.setText(qk1.jb4.getText());
}
});
qk1.jb5.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
qk1.jt1.setText(qk1.jb5.getText());
}
});
qk1.jb6.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
qk1.jt1.setText(qk1.jb6.getText());
}
});
//取款选项中的第7个按钮是用于返回主菜单
qk1.jb7.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
qk1.dispose();
cd1.setVisible(true);
}
});
//取款中的第8个按钮是用于确定取款额度
qk1.jb8.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
double s=Double.valueOf(qk1.jt1.getText());
if(s>Double.valueOf(cunkuan))
{
JOptionPane.showMessageDialog(null,"您要求的金额大于您的存款,请重新选择金额。");
qk1.jt1.setText("");
}
else
{
JOptionPane.showMessageDialog(null,"取款成功,请保管好您的财务。");
cunkuan-=s;
qk1.jt1.setText("");
}
}
});
}
});
//点击第二个按钮,进入查询余额选项
cd1.jb2.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
final Chaxun cx1=new Chaxun();
cd1.setVisible(false);
cx1.setVisible(true);
cx1.jt1.setText(Double.toString(cunkuan));
cx1.jb1.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
cx1.dispose();
cd1.setVisible(true);
}
});
}
});
//点击第三个按钮,进入修改密码选项
cd1.jb3.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
final Xiugai xg1=new Xiugai();
cd1.setVisible(false);
xg1.setVisible(true);
xg1.jb1.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
if(xg1.jp1.getPassword().length==0||xg1.jp2.getPassword().length==0||xg1.jp3.getPassword().length==0)
{
JOptionPane.showMessageDialog(null,"原密码或者新密码不能为空。");
return;
}
if((String.valueOf(xg1.jp1.getPassword()).equals(mima))&&(xg1.jp2.getPassword().length!=0)&&(xg1.jp3.getPassword().length!=0)&&(String.valueOf(xg1.jp2.getPassword()).equals(String.valueOf(xg1.jp3.getPassword()))))
{
JOptionPane.showMessageDialog(null,"修改密码成功。");
mima=String.valueOf(xg1.jp2.getPassword());
xg1.jp1.setText("");
xg1.jp2.setText("");
xg1.jp3.setText("");
return;
}
else
{
JOptionPane.sh