ATM柜员机人机界面

ATM柜员机模拟程序

/*账户1234567890密码123456*/
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.File;
import javax.swing.*;
public class ATM柜员机模拟程序 {
		 static String mima ="123456";
		 double cunqian = 0;
		 double quqian = 0;
		 double yue=0;
	private ATM柜员机模拟程序() throws Exception {
		File destDir=null;
		File destFile=null;
		destDir = new File("D:\\code");
		if(!destDir.exists()) {
			destDir.mkdir();
		}
		destFile = new File(destDir,"code.txt");
		if(!destFile.exists()) {
			destFile.createNewFile();
		}
		JFrame frm1 = new JFrame();
		frm1.setLayout(null);
		JTextArea text1 = new JTextArea("\n 欢迎使用网上银行自助服务");
		JTextArea text2 = new JTextArea();
		JPasswordField text3 = new JPasswordField();
		JButton btn = new JButton("< 登      录 >");
		frm1.add(btn);
		btn.setBackground(Color.red);
		Font g = new Font("楷体",Font.BOLD,20);
		btn.setFont(g);
		btn.setBounds(280, 250, 200, 100);
		frm1.add(text1 );
		frm1.add(text2);
		frm1.add(text3);
		JLabel lab1,lab2; 
		lab1 = new JLabel("账   号:");
		lab2 = new JLabel("密   码:");
		frm1.add(lab1);
		frm1.add(lab2);
		text1.setBounds(10, 20, 460, 120);
		lab1.setBounds(50, 150, 100, 20);
		lab2.setBounds(50, 180, 100, 20);
		frm1.setBounds(500, 400, 500, 400);
		text2.setBounds(150, 150, 100,20);
		text3.setBounds(150, 180, 100, 20);
		text1.setBackground(Color.BLUE);
		Font f = new Font("黑体",Font.BOLD,33);
		text1.setFont(f);
		text1.setForeground(Color.RED);
		lab1.setForeground(Color.gray);
		lab2.setForeground(Color.gray);
		text1.setEditable(false);
		frm1.setVisible(true);
		frm1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		btn.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				@SuppressWarnings("deprecation")
				String password = text3.getText();
				if(text2.getText().toString().equals("1234567890")&&password.equals(mima)) {frm1.setVisible(false);set();}
				else new JDialog();
			}
			
		});
		
		}
	private void set() {
		JButton btn1,btn2,btn3,btn4,btn5,btn6;
		JTextArea text1;
		JFrame frm = new JFrame();
		text1 = new JTextArea();
		btn1 = new JButton("余额查询");
		btn2 = new JButton("取       款");
		btn3 = new JButton("存       钱");
		btn4 = new JButton("密码修改");
		btn5 = new JButton(" < 退 出");
		btn6 = new JButton(" 遇 到 问 题 > ");
		frm.add(text1);
		frm.add(btn1);
		frm.add(btn2);
		frm.add(btn3);
		frm.add(btn4);
		frm.add(btn5);
		frm.add(btn6);
		frm.setVisible(true);
		frm.setBounds(500, 400, 500, 400);
		frm.setLayout(null);
		text1.setBounds(0, 0, 300, 300);
		Font f = new Font("",Font.BOLD,33);
		text1.setText("\n\n☺ 您好 , 欢迎使用\n              ATM !");
		text1.setFont(f);
		text1.setForeground(Color.gray);
		text1.setBackground(Color.BLUE);
		text1.setEditable(false);
		btn1.setBounds(300,0,200,100);
		btn1.setBackground(Color.cyan);
		btn2.setBounds(300,100,200,50);
		btn2.setBackground(Color.cyan);
		btn3.setBounds(300,150,200,100);
		btn3.setBackground(Color.cyan);
		btn4.setBounds(300,250,200,50);
		btn4.setBackground(Color.cyan);
		btn5.setBackground(Color.RED);
		btn6.setBackground(Color.GREEN);
		btn5.setBounds(0, 300, 200, 35);
		btn6.setBounds(300, 300, 200, 35);
		frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
			
		
		btn1.addMouseListener(new MouseListener() {
			public void mouseClicked(MouseEvent arg0) {
				JOptionPane.showMessageDialog(null, "您的可用余额为"+yue+"元","余额查询",JOptionPane.PLAIN_MESSAGE);
				}
			public void mouseEntered(MouseEvent arg0) {btn1.setBackground(Color.red);}
			public void mouseExited(MouseEvent arg0) {btn1.setBackground(Color.CYAN);}
			public void mousePressed(MouseEvent arg0) {}
			public void mouseReleased(MouseEvent arg0) {}});
		btn2.addMouseListener(new MouseListener() {
			public void mouseClicked(MouseEvent arg0) {
				JFrame frm = new JFrame();
				frm.setLayout(null);
				frm.setBounds(500, 400, 300, 250);
				JButton btn1 = new JButton("确 定");
				JLabel lab = new JLabel("请输入要提取的金额");
				lab.setBounds(50, 25, 150, 25);
				lab.setForeground(Color.gray);
				JTextArea text = new JTextArea();
				text.setBounds(50, 60, 100, 20);
				text.setBackground(Color.gray);
				frm.add(text);
				frm.add(lab);
				btn1.setBounds(150, 150, 100, 20);
				frm.add(btn1);
				btn1.setBackground(Color.red);
				frm.setVisible(true);
				btn1.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent arg0) {
						frm.setVisible(false);
						quqian = Double.valueOf(text.getText());
						if(yue<quqian)JOptionPane.showMessageDialog(null, "余额不足,请充值", "取钱",JOptionPane.PLAIN_MESSAGE);
						else{yue = yue-quqian;
						JOptionPane.showMessageDialog(null, "提取金额"+quqian+"成功", "取钱",JOptionPane.PLAIN_MESSAGE);
						}
						
					}
				});
			}
			public void mouseEntered(MouseEvent arg0) {btn2.setBackground(Color.red);}
			public void mouseExited(MouseEvent arg0) {btn2.setBackground(Color.CYAN);}
			public void mousePressed(MouseEvent arg0) {}
			public void mouseReleased(MouseEvent arg0) {}
			});
		btn3.addMouseListener(new MouseListener() {
			public void mouseClicked(MouseEvent arg0) {
				JFrame frm = new JFrame();
				frm.setLayout(null);
				frm.setBounds(500, 400, 300, 250);
				JButton btn1 = new JButton("确 定");
				JLabel lab = new JLabel("请输入要存入的金额");
				lab.setBounds(50, 25, 150, 25);
				lab.setForeground(Color.gray);
				JTextArea text = new JTextArea();
				text.setBounds(50, 60, 100, 20);
				text.setBackground(Color.gray);
				frm.add(text);
				frm.add(lab);
				btn1.setBounds(150, 150, 100, 20);
				frm.add(btn1);
				btn1.setBackground(Color.red);
				frm.setVisible(true);
				btn1.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent arg0) {
						cunqian = Double.valueOf(text.getText());
						yue = yue+cunqian;
						frm.setVisible(false);
						JOptionPane.showMessageDialog(null, "存入金额"+cunqian+"成功", "存钱",JOptionPane.PLAIN_MESSAGE);
					}
				});
			}
			public void mouseEntered(MouseEvent arg0) {btn3.setBackground(Color.red);}
			public void mouseExited(MouseEvent arg0) {btn3.setBackground(Color.CYAN);}
			public void mousePressed(MouseEvent arg0) {}
			public void mouseReleased(MouseEvent arg0) {}
			});
		btn4.addMouseListener(new MouseListener() {
			public void mouseClicked(MouseEvent arg0) {
				JFrame frm = new JFrame();
				frm.setLayout(null);
				frm.setBounds(500, 400, 300, 250);
				JButton btn1 = new JButton("确 定");
				JLabel lab = new JLabel("请输入要修改的密码");
				lab.setBounds(50, 25, 150, 25);
				lab.setForeground(Color.gray);
				JTextArea text = new JTextArea();
				text.setBounds(50, 60, 100, 20);
				text.setBackground(Color.gray);
				frm.add(text);
				frm.add(lab);
				btn1.setBounds(150, 150, 100, 20);
				frm.add(btn1);
				btn1.setBackground(Color.red);
				frm.setVisible(true);
				btn1.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent arg0) {
						mima=text.getText().toString();
						frm.setVisible(false);
						JOptionPane.showMessageDialog(null, "修改密码成功,请记住你的当前密码", "修改密码",JOptionPane.PLAIN_MESSAGE);
					}
				});
			}
			public void mouseEntered(MouseEvent arg0) {btn4.setBackground(Color.RED);}
			public void mouseExited(MouseEvent arg0) {btn4.setBackground(Color.CYAN);}
			public void mousePressed(MouseEvent arg0) {}
			public void mouseReleased(MouseEvent arg0) {}
		});
		btn5.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				frm.setVisible(false);
				try {
					new ATM柜员机模拟程序();
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
		btn6.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				JOptionPane.showMessageDialog(null, "请咨询:客服电话:198********\n"+"                  qq :2424******", "遇到问题",JOptionPane.QUESTION_MESSAGE);
			}										
		});
		
	}

	public static void main(String[] args) throws Exception {
		 new ATM柜员机模拟程序();
	}
}

这里是登录界面
这里是登录进去之后
这里是存入金额
这里是提取金额
这里是余额查询

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值