⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mainframe.java

📁 模拟ATM取款机
💻 JAVA
字号:
package com.zfz.view;

import java.awt.Color;
import java.awt.Font;
import java.awt.GridLayout;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.border.LineBorder;

import com.zfz.atmInter.FileName;
import com.zfz.controller.CancelHandler;
import com.zfz.controller.CardHandler;
import com.zfz.controller.ChangeHandler;
import com.zfz.controller.ComFHandler;
import com.zfz.controller.DowMoneyButHandler;
import com.zfz.controller.DowMoneyHandler;
import com.zfz.controller.NoHandler;
import com.zfz.controller.NumHandler;
import com.zfz.controller.ResetpasswardHandler;
import com.zfz.controller.ReturnSelHandler;
import com.zfz.controller.SearchHandler;
import com.zfz.controller.TransferAccount;
import com.zfz.controller.WithdrawHandler;
import com.zfz.controller.YesHandler;
import com.zfz.model.Account;
import com.zfz.model.DAO.ObjectInandOut;

public class MainFrame extends JFrame {
	private static final long serialVersionUID = -2396715772267784109L;
	private JPanel tPane, tlPane, trPane, vPane, bPane, numPane, opPane;
	private JButton numBut[], opBut[], moneyBut, cardBut, viewBut[];
	private JLabel mainLab, opLab[];
	private JTextField fd;
	private int viewNum = 0;
	private Account[] acc;
	private int accIndex;// 记录当前操作用户所在数组的位置
	private static int inputCount;// 记录密码输入次数
	private static String cardNo;
	private ObjectInandOut acc_out_in;

	public MainFrame() {
		super("ATM 模型");
		inputCount = 0;
		acc_out_in = new ObjectInandOut(FileName.accFile);
		new ObjectInandOut(FileName.sysFile);
		acc = acc_out_in.myReadObj();
		accIndex = -1;

		this.setBounds(200, 200, 400, 500);
		this.setLayout(null);
		LineBorder lineBor = new LineBorder(Color.BLACK);

		tlPane = new JPanel();
		tlPane.setBounds(5, 5, 85, 175);
		tlPane.setLayout(new GridLayout(4, 1, 0, 5));

		trPane = new JPanel();
		trPane.setBounds(292, 5, 85, 175);
		trPane.setLayout(new GridLayout(4, 1, 0, 5));

		// 屏幕旁按钮
		viewBut = new JButton[8];
		int index = 0;
		for (int i = 0; i < viewBut.length; i++) {
			if (i < 4) {
				viewBut[i] = new JButton("===>");
				tlPane.add(viewBut[i]);
			} else {
				viewBut[i] = new JButton("<===");
				trPane.add(viewBut[i]);
			}
		}

		tPane = new JPanel();
		tPane.setBorder(lineBor);
		tPane.setLayout(null);
		tPane.setBounds(5, 3, 382, 185);
		tPane.add(tlPane);
		tPane.add(trPane);
		this.add(tPane);

		// 取款按钮
		viewBut[0].addActionListener(new DowMoneyHandler(this));
		// 返回按钮
		viewBut[1].addActionListener(new ReturnSelHandler(this));
		// 修改密码
		viewBut[2].addActionListener(new ResetpasswardHandler(this));
		// 取卡
		viewBut[3].addActionListener(new WithdrawHandler(this));
		// 查询按钮
		viewBut[4].addActionListener(new SearchHandler(this));
		// 转账
		viewBut[5].addActionListener(new TransferAccount(this));
		// 是
		viewBut[6].addActionListener(new YesHandler(this));
		// 否
		viewBut[7].addActionListener(new NoHandler(this));

		// 屏幕
		vPane = new JPanel();
		vPane.setBackground(Color.BLUE);
		vPane.setLayout(null);
		vPane.setBounds(95, 5, 193, 175);
		tPane.add(vPane);

		fd = new JTextField();
		fd.setBounds(20, 100, 150, 30);
		fd.setHorizontalAlignment(JTextField.RIGHT);
		vPane.add(fd);

		// 提示标签
		mainLab = new JLabel("欢迎使用,请插卡");
		mainLab.setHorizontalAlignment(JLabel.CENTER);
		mainLab.setFont(new Font("黑体", Font.PLAIN, 18));
		mainLab.setBounds(1, 25, 190, 50);
		mainLab.setForeground(Color.WHITE);
		vPane.add(mainLab);

		// 操作标签
		String[] name = { "取款", "返回", "修改密码", "取卡", "查询", "转账", "是", "否" };
		int[] lposi = { 5, 10, 5, 50, 5, 95, 5, 140, 128, 10, 128, 50, 128, 95,
				128, 140 };
		int indexN = 0;
		int indexP = 0;
		opLab = new JLabel[8];
		for (int i = 0; i < opLab.length; i++) {
			opLab[i] = new JLabel(name[indexN++]);
			opLab[i].setBounds(lposi[indexP++], lposi[indexP++], 60, 40);
			opLab[i].setForeground(Color.WHITE);
			opLab[i].setFont(new Font("黑体", Font.PLAIN, 15));
			if (i < 4) {
				opLab[i].setHorizontalAlignment(JLabel.LEFT);
			} else {
				opLab[i].setHorizontalAlignment(JLabel.RIGHT);
			}
			vPane.add(opLab[i]);
		}
		// 中间面板
		moneyBut = new JButton("[____________取款___________]");
		moneyBut.setBounds(5, 197, 245, 50);
		moneyBut.addActionListener(new DowMoneyButHandler(this));
		cardBut = new JButton("[__插卡处__]");
		cardBut.setBounds(265, 197, 122, 50);
		cardBut.addActionListener(new CardHandler(this));
		this.add(moneyBut);
		this.add(cardBut);

		// 南部面板
		bPane = new JPanel();
		bPane.setLayout(null);
		bPane.setBounds(5, 255, 382, 185);
		bPane.setBorder(lineBor);
		this.add(bPane);
		// 数字键
		numBut = new JButton[12];
		numPane = new JPanel();
		numPane.setLayout(new GridLayout(4, 3, 5, 5));
		numPane.setBounds(5, 5, 200, 175);
		bPane.add(numPane);

		String numStr[] = { "7", "8", "9", "4", "5", "6", "1", "2", "3", ".",
				"0", "00" };
		int nIndex = 0;
		for (int i = 0; i < numBut.length; i++) {
			numBut[i] = new JButton(numStr[nIndex++]);
			numPane.add(numBut[i]);
			numBut[i].addActionListener(new NumHandler(this, i));
		}

		// 操作按钮
		opPane = new JPanel();
		opPane.setBounds(260, 5, 100, 175);
		opPane.setLayout(new GridLayout(3, 1, 10, 10));

		String strName[] = { "更改", "取消", "确认" };
		index = 0;
		opBut = new JButton[3];
		for (int i = 0; i < opBut.length; i++) {
			opBut[i] = new JButton(strName[index++]);
			opPane.add(opBut[i]);
		}
		// 更改
		opBut[0].addActionListener(new ChangeHandler(this));
		// 取消
		opBut[1].addActionListener(new CancelHandler(this));
		// 确定按钮
		opBut[2].addActionListener(new ComFHandler(this));

		bPane.add(opPane);
		this.add(bPane);

		this.setVisible(true);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setProPety();
	}

	public JPanel getTPane() {
		return tPane;
	}

	public JPanel getVPane() {
		return vPane;
	}

	public JPanel getBPane() {
		return bPane;
	}

	public JPanel getNumPane() {
		return numPane;
	}

	public JPanel getOpPane() {
		return opPane;
	}

	public JButton[] getNumBut() {
		return numBut;
	}

	public JButton[] getOpBut() {
		return opBut;
	}

	public JButton getMoneyBut() {
		return moneyBut;
	}

	public JButton getCardBut() {
		return cardBut;
	}

	public JButton[] getViewBut() {
		return viewBut;
	}

	public JLabel getMainLab() {
		return mainLab;
	}

	public JLabel[] getOpLab() {
		return opLab;
	}

	public JTextField getFd() {
		return fd;
	}

	public int getViewNum() {
		return viewNum;
	}

	public void setViewNum(int viewNum) {
		this.viewNum = viewNum;
	}

	// -1 吞卡 0-欢迎 2-输入密码 3-选择界面 4-取款 5-查询
	// 6-转账 7-转账金额 8-修改密码 9-确认密码 10-凭条
	public void setProPety() {
		if (viewNum == -1) {// 吞卡
			boolean[] b = { false, false, false, false, false, false, false,
					false, true, false };
			setVisible(b);
			this.getMainLab().setText("密码三次错误,吞卡");
		}
		if (viewNum == 0) {// 欢迎
			boolean[] b = { false, false, false, false, false, false, false,
					false, true, false };
			setVisible(b);
		}
		if (viewNum == 2) {// 输入密码
			boolean[] b = { false, false, false, false, false, false, false,
					false, true, true };
			this.getFd().setText("");
			if (inputCount < 1)
				this.getMainLab().setText("请输入密码");
			else
				this.getMainLab().setText("密码错误,请重新输入");
			setVisible(b);
		}

		if (viewNum == 3) {// 选择界面
			boolean[] b = { true, false, true, true, true, true, false, false,
					true, false };
			this.getMainLab().setText("请选择操作");
			fd.setText("");
			setVisible(b);
		}

		if (viewNum == 4) {// 取款
			boolean[] b = { false, true, false, false, false, false, false,
					false, true, true };
			this.getMainLab().setText("请输入取款金额");
			setVisible(b);
		}
		if (viewNum == 5) {// 查询
			boolean[] b = { false, true, false, false, false, false, false,
					false, true, false };
			this.getMainLab().setText("您的余额:");
			setVisible(b);
		}
		if (viewNum == 6) {// 转账
			boolean[] b = { false, true, false, false, false, false, false,
					false, true, true };
			this.getMainLab().setText("请输入转账账号");
			setVisible(b);
		}
		if (viewNum == 7) {
			boolean[] b = { false, true, false, false, false, false, false,
					false, true, true };
			this.getFd().setText("");
			this.getMainLab().setText("请输入转账金额");
			setVisible(b);
		}
		if (viewNum == 8) {// 修改密码
			boolean[] b = { false, true, false, false, false, false, false,
					false, true, true };
			this.getMainLab().setText("请输入新密码");
			setVisible(b);
		}
		if (viewNum == 9) {// 确认密码
			boolean[] b = { false, true, false, false, false, false, false,
					false, true, true };
			this.getFd().setText("");
			this.getMainLab().setText("请重新输入新密码");
			setVisible(b);
		}
		if (viewNum == 10) {// 凭条
			boolean[] b = { false, true, false, false, false, false, true,
					true, true, false };
			this.getMainLab().setText("是否打印凭条");
			setVisible(b);
		}
	}

	public void setVisible(boolean b[]) {
		for (int i = 0; i < opLab.length; i++) {
			opLab[i].setVisible(b[i]);
		}
		mainLab.setVisible(b[8]);
		fd.setVisible(b[9]);
	}

	public Account[] getAcc() {
		return acc;
	}

	public void setAcc(Account[] acc) {
		this.acc = acc;
	}

	public int getAccIndex() {
		return accIndex;
	}

	public void setAccIndex(int accIndex) {
		this.accIndex = accIndex;
	}

	public ObjectInandOut getAcc_out_in() {
		return acc_out_in;
	}

	public void setAcc_out_in(ObjectInandOut acc_out_in) {
		this.acc_out_in = acc_out_in;
	}

	public static int getInputCount() {
		return inputCount;
	}

	public static void setInputCount(int inputCount) {
		MainFrame.inputCount = inputCount;
	}

	public static String getCardNo() {
		return cardNo;
	}

	public static void setCardNo(String cardNo) {
		MainFrame.cardNo = cardNo;
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -