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

📄 banksystem.java

📁 一个用java做的银行系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.util.*;
import java.text.*;
import java.io.*;
import java.awt.PrintJob.*;
import javax.swing.plaf.metal.*;

public class BankSystem extends JFrame implements ActionListener, ItemListener {

	//Main Place on Form where All Child Forms will Shown.
	private JDesktopPane desktop = new JDesktopPane ();

	//For Program's MenuBar.
	private JMenuBar bar;

	//All the Main Menu of the Program.
	private JMenu mnuFile, mnuEdit, mnuView, mnuOpt, mnuWin, mnuHelp;

	private JMenuItem addNew, printRec, end;				//File Menu Options.
	private	JMenuItem deposit, withdraw, delRec, search, searchName;	//Edit Menu Options.
	private	JMenuItem oneByOne, allCustomer;				//View Menu Options.
	private	JMenuItem change, style, theme;					//Option Menu Options.
	private JMenuItem close, closeAll;					//Window Menu Options.
	private	JMenuItem content, keyHelp, about;				//Help Menu Options.

	//PopupMenu of Program.
	private JPopupMenu popMenu = new JPopupMenu ();

	//MenuItems for PopupMenu of the Program.
	private JMenuItem open, report, dep, with, del, find, all;

	//For Program's ToolBar.
	private	JToolBar toolBar;

	//For ToolBar's Button.
	private	JButton btnNew, btnDep, btnWith, btnRec, btnDel, btnSrch, btnHelp, btnKey;

	//Main Form StatusBar where Program's Name & Welcome Message Display.
	private JPanel statusBar = new JPanel ();

	//Labels for Displaying Program's Name & saying Welcome to Current User on StatusBar.
	private JLabel welcome;
	private JLabel author;

	//Making the LookAndFeel Menu.
	private String strings[] = {"1. Metal", "2. Motif", "3. Windows"};
	private UIManager.LookAndFeelInfo looks[] = UIManager.getInstalledLookAndFeels ();
	private ButtonGroup group = new ButtonGroup ();
	private JRadioButtonMenuItem radio[] = new JRadioButtonMenuItem[strings.length];

	//Getting the Current System Date.
	private java.util.Date currDate = new java.util.Date ();
	private SimpleDateFormat sdf = new SimpleDateFormat ("dd MMMM yyyy", Locale.getDefault());
	private String d = sdf.format (currDate);

	//Following all Variables are use in BankSystem's IO's.

	//Variable use in Reading the BankSystem Records File & Store it in an Array.
	private int count = 0;
	private int rows = 0;
	private	int total = 0;

	//String Type Array use to Load Records From File.
	private String records[][] = new String [500][6];

	//Variable for Reading the BankSystem Records File.
	private FileInputStream fis;
	private DataInputStream dis;

	//Constructor of The Bank Program to Iniatilize all Variables of Program.

	public BankSystem () {

		//Setting Program's Title.
		super ("BankSystem [Pvt] Limited.");

		UIManager.addPropertyChangeListener (new UISwitchListener ((JComponent)getRootPane()));

		//Creating the MenuBar.
		bar = new JMenuBar ();

		//Setting the Main Window of Program.
		setIconImage (getToolkit().getImage ("Images/Bank.gif"));
		setSize (700, 550);
		setJMenuBar (bar);

		//Closing Code of Main Window.
		addWindowListener (new WindowAdapter () {
			public void windowClosing (WindowEvent we) {
				quitApp ();
			}
		}
		);

		//Setting the Location of Application on Screen.
		setLocation((Toolkit.getDefaultToolkit().getScreenSize().width  - getWidth()) / 2,
			(Toolkit.getDefaultToolkit().getScreenSize().height - getHeight()) / 2);

		//Creating the MenuBar Items.
		mnuFile = new JMenu ("File");
		mnuFile.setMnemonic ((int)'F');
		mnuEdit = new JMenu ("Edit");
		mnuEdit.setMnemonic ((int)'E');
		mnuView = new JMenu ("View");
		mnuView.setMnemonic ((int)'V');
		mnuOpt = new JMenu ("Options");
		mnuOpt.setMnemonic ((int)'O');
		mnuWin = new JMenu ("Window");
		mnuWin.setMnemonic ((int)'W');
		mnuHelp = new JMenu ("Help");
		mnuHelp.setMnemonic ((int)'H');

		//Creating the MenuItems of Program.
		//MenuItems for FileMenu.
		addNew = new JMenuItem ("Open New Account", new ImageIcon ("Images/Open.gif"));
		addNew.setAccelerator (KeyStroke.getKeyStroke(KeyEvent.VK_N, Event.CTRL_MASK));
		addNew.setMnemonic ((int)'N');
		addNew.addActionListener (this);
		printRec = new JMenuItem ("Print Customer Balance", new ImageIcon ("Images/New.gif"));
		printRec.setAccelerator (KeyStroke.getKeyStroke(KeyEvent.VK_R, Event.CTRL_MASK));
		printRec.setMnemonic ((int)'R');
		printRec.addActionListener (this);
		end = new JMenuItem ("Quit BankSystem ?", new ImageIcon ("Images/export.gif"));
		end.setAccelerator (KeyStroke.getKeyStroke(KeyEvent.VK_Q, Event.CTRL_MASK));
		end.setMnemonic ((int)'Q');	
		end.addActionListener (this);

		//MenuItems for EditMenu.
		deposit = new JMenuItem ("Deposit Money");
		deposit.setAccelerator (KeyStroke.getKeyStroke(KeyEvent.VK_T, Event.CTRL_MASK));
		deposit.setMnemonic ((int)'T');
		deposit.addActionListener (this);
		withdraw = new JMenuItem ("Withdraw Money");
		withdraw.setAccelerator (KeyStroke.getKeyStroke(KeyEvent.VK_W, Event.CTRL_MASK));
		withdraw.setMnemonic ((int)'W');	
		withdraw.addActionListener (this);
		delRec = new JMenuItem ("Delete Customer", new ImageIcon ("Images/Delete.gif"));
		delRec.setAccelerator (KeyStroke.getKeyStroke(KeyEvent.VK_D, Event.CTRL_MASK));
		delRec.setMnemonic ((int)'D');
		delRec.addActionListener (this);
		search = new JMenuItem ("Search By No.", new ImageIcon ("Images/find.gif"));
		search.setAccelerator (KeyStroke.getKeyStroke(KeyEvent.VK_S, Event.CTRL_MASK));
		search.setMnemonic ((int)'S');	
		search.addActionListener (this);
		searchName = new JMenuItem ("Search By Name");
		searchName.setAccelerator (KeyStroke.getKeyStroke(KeyEvent.VK_M, Event.CTRL_MASK));
		searchName.setMnemonic ((int)'M');
		searchName.addActionListener (this);

		//MenuItems for ViewMenu.
		oneByOne = new JMenuItem ("View One By One");
		oneByOne.setAccelerator (KeyStroke.getKeyStroke(KeyEvent.VK_O, Event.CTRL_MASK));
		oneByOne.setMnemonic ((int)'O');	
		oneByOne.addActionListener (this);
		allCustomer = new JMenuItem ("View All Customer", new ImageIcon ("Images/refresh.gif"));
		allCustomer.setAccelerator (KeyStroke.getKeyStroke(KeyEvent.VK_A, Event.CTRL_MASK));
		allCustomer.setMnemonic ((int)'A');
		allCustomer.addActionListener (this);

		//MenuItems for OptionMenu.
		change = new JMenuItem ("Change Background Color");
		change.setAccelerator (KeyStroke.getKeyStroke(KeyEvent.VK_B, Event.CTRL_MASK));
		change.setMnemonic ((int)'B');
		change.addActionListener (this);
		//Menu For Changing the Program's Layout.
		style = new JMenu ("Change Layout Style");
		style.setMnemonic ((int)'L');
		for( int i = 0; i < radio.length ; i++ ) {			//Creating the subMenus of Style Menu.
			radio[i] = new JRadioButtonMenuItem (strings[i]);	//Build an Array of Layouts to Apply.
			radio[i].addItemListener (this);			//Setting their Actions.
			group.add (radio[i]);					//Making them Grouped.
			style.add (radio[i]);					//Adding to Style MenuOption.
		}
		//SubMenu of Theme For Applying different Themes to Program By Building an Array of Themes to Apply.
		MetalTheme[] themes = { new DefaultMetalTheme(), new GreenTheme(), new AquaTheme(), 
					new SandTheme(), new SolidTheme(), new MilkyTheme(), new GrayTheme() };
		theme = new MetalThemeMenu ("Apply Theme", themes);		//Putting the Themes in ThemeMenu.
		theme.setMnemonic ((int)'M');

		//MenuItems for WindowMenu.
		close = new JMenuItem ("Close Active Window");
		close.setMnemonic ((int)'C');
		close.addActionListener (this);
		closeAll = new JMenuItem ("Close All Windows...");
		closeAll.setMnemonic ((int)'A');
		closeAll.addActionListener (this);

		//MenuItems for HelpMenu.
		content = new JMenuItem ("Help Contents", new ImageIcon ("Images/paste.gif"));
		content.setAccelerator (KeyStroke.getKeyStroke(KeyEvent.VK_H, Event.CTRL_MASK));
		content.setMnemonic ((int)'H');
		content.addActionListener (this);
		keyHelp = new JMenuItem ("Help on Shortcuts...");
		keyHelp.setAccelerator (KeyStroke.getKeyStroke(KeyEvent.VK_K, Event.CTRL_MASK));
		keyHelp.setMnemonic ((int)'K');
		keyHelp.addActionListener (this);
		about = new JMenuItem ("About BankSystem", new ImageIcon ("Images/Save.gif"));
		about.setAccelerator (KeyStroke.getKeyStroke(KeyEvent.VK_C, Event.CTRL_MASK));
		about.setMnemonic ((int)'C');
		about.addActionListener (this);

		//Adding MenuItems to Menu.
	
		//File Menu Items.
		mnuFile.add (addNew);
		mnuFile.addSeparator ();
		mnuFile.add (printRec);
		mnuFile.addSeparator ();
		mnuFile.add (end);

		//Edit Menu Items.
		mnuEdit.add (deposit);
		mnuEdit.add (withdraw);
		mnuEdit.addSeparator ();
		mnuEdit.add (delRec);
		mnuEdit.addSeparator ();
		mnuEdit.add (search);
		mnuEdit.add (searchName);

		//View Menu Items.
		mnuView.add (oneByOne);
		mnuView.addSeparator ();
		mnuView.add (allCustomer);

		//Options Menu Items.
		mnuOpt.add (change);
		mnuOpt.addSeparator ();
		mnuOpt.add (style);
		mnuOpt.addSeparator ();
		mnuOpt.add (theme);

		//Window Menu Items.
		mnuWin.add (close);
		mnuWin.add (closeAll);

		//Help Menu Items.
		mnuHelp.add (content);
		mnuHelp.addSeparator ();
		mnuHelp.add (keyHelp);
		mnuHelp.addSeparator ();
		mnuHelp.add (about);

		//Adding Menues to Bar.
		bar.add (mnuFile);
		bar.add (mnuEdit);
		bar.add (mnuView);
		bar.add (mnuOpt);
		bar.add (mnuWin);
		bar.add (mnuHelp);

		//MenuItems for PopupMenu.
		open = new JMenuItem ("Open New Account", new ImageIcon ("Images/Open.gif"));
		open.addActionListener (this);
		report = new JMenuItem ("Print BankSystem Report", new ImageIcon ("Images/New.gif"));
		report.addActionListener (this);
		dep = new JMenuItem ("Deposit Money");
		dep.addActionListener (this);
		with = new JMenuItem ("Withdraw Money");
		with.addActionListener (this);
		del = new JMenuItem ("Delete Customer", new ImageIcon ("Images/Delete.gif"));
		del.addActionListener (this);
		find = new JMenuItem ("Search Customer", new ImageIcon ("Images/find.gif"));
		find.addActionListener (this);
		all = new JMenuItem ("View All Customer", new ImageIcon ("Images/refresh.gif"));
		all.addActionListener (this);

		//Adding Menues to PopupMenu.
		popMenu.add (open);
		popMenu.add (report);
		popMenu.add (dep);
		popMenu.add (with);
		popMenu.add (del);
		popMenu.add (find);
		popMenu.add (all);

		//Following Procedure display the PopupMenu of Program.
		addMouseListener (new MouseAdapter () {
			public void mousePressed (MouseEvent me) { checkMouseTrigger (me); }
			public void mouseReleased (MouseEvent me) { checkMouseTrigger (me); }
			private void checkMouseTrigger (MouseEvent me) {
				if (me.isPopupTrigger ())
					popMenu.show (me.getComponent (), me.getX (), me.getY ());
			}
		}
		);
		
		//Creating the ToolBar's Buttons of Program.
		btnNew = new JButton (new ImageIcon ("Images/NotePad.gif"));
		btnNew.setToolTipText ("Create New Account");
		btnNew.addActionListener (this);
		btnDep = new JButton (new ImageIcon ("Images/ImationDisk.gif"));
		btnDep.setToolTipText ("Deposit Money");
		btnDep.addActionListener (this);
		btnWith = new JButton (new ImageIcon ("Images/SuperDisk.gif"));
		btnWith.setToolTipText ("Withdraw Money");
		btnWith.addActionListener (this);
		btnRec = new JButton (new ImageIcon ("Images/Paproll.gif"));
		btnRec.setToolTipText ("Print Customer Balance");
		btnRec.addActionListener (this);
		btnDel = new JButton (new ImageIcon ("Images/Toaster.gif"));
		btnDel.setToolTipText ("Delete Customer");
		btnDel.addActionListener (this);
		btnSrch = new JButton (new ImageIcon ("Images/Search.gif"));
		btnSrch.setToolTipText ("Search Customer");
		btnSrch.addActionListener (this);
		btnHelp = new JButton (new ImageIcon ("Images/Help.gif"));
		btnHelp.setToolTipText ("Help on Bank System");
		btnHelp.addActionListener (this);
		btnKey = new JButton (new ImageIcon ("Images/Keys.gif"));
		btnKey.setToolTipText ("Shortcut Keys of BankSystem");
		btnKey.addActionListener (this);

		//Creating the ToolBar of Program.
		toolBar = new JToolBar ();
		toolBar.add (btnNew);
		toolBar.addSeparator ();
		toolBar.add (btnDep);
		toolBar.add (btnWith);
		toolBar.addSeparator ();
		toolBar.add (btnRec);
		toolBar.addSeparator ();
		toolBar.add (btnDel);
		toolBar.addSeparator ();
		toolBar.add (btnSrch);
		toolBar.addSeparator ();
		toolBar.add (btnHelp);
		toolBar.add (btnKey);

		//Creating the StatusBar of Program.
		author = new JLabel (" " + "BankSystem [Pvt] Limited.", Label.LEFT);
		author.setForeground (Color.black);
		author.setToolTipText ("Program's Title");
		welcome = new JLabel ("Welcome Today is " + d + " ", JLabel.RIGHT);
		welcome.setForeground (Color.black);
		welcome.setToolTipText ("Welcoming the User & System Current Date");
		statusBar.setLayout (new BorderLayout());
		statusBar.add (author, BorderLayout.WEST);
		statusBar.add (welcome, BorderLayout.EAST);

		//For Making the Dragging Speed of Internal Frames Faster.
		desktop.putClientProperty ("JDesktopPane.dragMode", "outline");

		//Setting the Contents of Programs.
		getContentPane().add (toolBar, BorderLayout.NORTH);
		getContentPane().add (desktop, BorderLayout.CENTER);
		getContentPane().add (statusBar, BorderLayout.SOUTH);

		//Showing The Main Form of Application.
		setVisible (true);

	}

	//Function For Performing different Actions By Menus of Program.

	public void actionPerformed (ActionEvent ae) {
	
		Object obj = ae.getSource();

		if (obj == addNew || obj == open || obj == btnNew) {

			boolean b = openChildWindow ("Create New Account");
			if (b == false) {

⌨️ 快捷键说明

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