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

📄 newcustomerframe.java

📁 本程序用Java语言描述了一个基本的银行管理系统
💻 JAVA
字号:
package banking.applet;

import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import banking.domain.Bank;
import banking.domain.CheckingAccount;
import banking.domain.Customer;
import banking.domain.SavingsAccount;

public class NewCustomerFrame extends JFrame {
	JPanel jpAccInfo = new JPanel();

	JPanel[] jpAccInfoLittle = new JPanel[Customer.MAX_CAPACITY];

	JPanel jpNameMessage = new JPanel();

	JPanel jpAccNumSel = new JPanel();

	JButton jbtOK = new JButton("OK");

	JComboBox jcbAccNumSel = new JComboBox();

	JComboBox[] jcbAccType = new JComboBox[Customer.MAX_CAPACITY];

	JTextField jtfFN = new JTextField(Customer.STRING_SIZE / 2);

	JTextField jtfLN = new JTextField(Customer.STRING_SIZE / 2);

	JTextField[] jtfBal = new JTextField[Customer.MAX_CAPACITY];

	JTextField[] jtfAdd = new JTextField[Customer.MAX_CAPACITY];

	public NewCustomerFrame() {
		this.setLayout(new BorderLayout());
		this.jpAccInfo.setLayout(new GridLayout(Customer.MAX_CAPACITY, 5, 10,
				10));
		this.jpAccNumSel.setLayout(new GridLayout(3, 1));
		this.jpNameMessage.setLayout(new GridLayout(1, 4));

		// jpAccInfo
		for (int i = 0; i < Customer.MAX_CAPACITY; ++i) {
			this.jpAccInfoLittle[i] = new JPanel();
			this.jpAccInfoLittle[i].setLayout(new GridLayout(2, 1));
			this.jcbAccType[i] = new JComboBox();
			this.jcbAccType[i].addItem("Savings Account");
			this.jcbAccType[i].addItem("Checking Account");
			JLabel jlbBal = new JLabel("Balance:");
			JLabel jlbAddInfo = new JLabel(
					"interestRare | overdraftProtection:");
			this.jpAccInfoLittle[i].add(this.jcbAccType[i]);
			this.jtfBal[i] = new JTextField();
			this.jtfAdd[i] = new JTextField();
			JPanel jpPart = new JPanel();
			jpPart.setLayout(new GridLayout(1, 4));
			jpPart.add(jlbBal);
			jpPart.add(this.jtfBal[i]);
			jpPart.add(jlbAddInfo);
			jpPart.add(this.jtfAdd[i]);
			this.jpAccInfoLittle[i].add(jpPart);
			this.jpAccInfo.add(this.jpAccInfoLittle[i]);
		}

		// jpAccNumSel
		JLabel jlbCB = new JLabel("please select number of accounts: ");
		this.jpAccNumSel.add(jlbCB);
		this.jpAccNumSel.add(this.jcbAccNumSel);
		for (int i = 0; i < Customer.MAX_CAPACITY; ++i) {
			this.jcbAccNumSel.addItem("" + (i + 1));
		}
		this.jcbAccNumSel.addItemListener(new ItemListener() {
			public void itemStateChanged(ItemEvent e) {
				changeNumSel();
			}
		});
		changeNumSel();

		// jpNameMessage
		JLabel jlbFN = new JLabel("FirstName: ");
		JLabel jlbLN = new JLabel("LastName: ");
		this.jpNameMessage.add(jlbFN);
		this.jpNameMessage.add(this.jtfFN);
		this.jpNameMessage.add(jlbLN);
		this.jpNameMessage.add(this.jtfLN);

		// jpButtons
		this.jpAccNumSel.add(this.jbtOK);
		this.jbtOK.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				formCustomer();
			}
		});

		this.add(this.jpNameMessage, BorderLayout.NORTH);
		this.add(this.jpAccNumSel, BorderLayout.SOUTH);
		this.add(this.jpAccInfo, BorderLayout.CENTER);
	}

	public void changeNumSel() {
		int num = Integer
				.parseInt((String) this.jcbAccNumSel.getSelectedItem());
		for (int i = 0; i < num; ++i) {
			this.jpAccInfoLittle[i].setVisible(true);
		}
		for (int i = num; i < Customer.MAX_CAPACITY; ++i)
			this.jpAccInfoLittle[i].setVisible(false);
	}

	public void formCustomer() {
		String f = this.jtfFN.getText();
		String l = this.jtfLN.getText();
		Customer c = new Customer(f, l);
		int num = this.jcbAccNumSel.getSelectedIndex() + 1;
		int accType = 0;
		for (int i = 0; i < num; ++i) {
			double balance = 0.0;
			double addition = 0.0;
			try {
				balance = Double.parseDouble(this.jtfBal[i].getText());
				addition = Double.parseDouble(this.jtfAdd[i].getText());
			} catch (Exception e) {
				e.printStackTrace();//
			}
			accType = this.jcbAccType[i].getSelectedIndex();
			if (0 == accType) {
				SavingsAccount sa = new SavingsAccount(balance, addition);
				c.addAccount(sa);
			} else {
				CheckingAccount ca = new CheckingAccount(balance, addition);
				c.addAccount(ca);
			}
		}
		Bank.getBank().addCustomer(c);
		this.dispose();
	}
}

⌨️ 快捷键说明

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