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

📄 banksystem.java

📁 一个用java做的银行系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
				NewAccount newAcc = new NewAccount ();
				desktop.add (newAcc);
				newAcc.show ();
			}

		}
		else if (obj == printRec || obj == btnRec || obj == report) {

			getAccountNo ();

		}
		else if (obj == end) {

			quitApp ();

		}
		else if (obj == deposit || obj == dep || obj == btnDep) {

			boolean b = openChildWindow ("Deposit Money");
			if (b == false) {
				DepositMoney depMon = new DepositMoney ();
				desktop.add (depMon);
				depMon.show ();
			}

		}
		else if (obj == withdraw || obj == with || obj == btnWith) {

			boolean b = openChildWindow ("Withdraw Money");
			if (b == false) {
				WithdrawMoney withMon = new WithdrawMoney ();
				desktop.add (withMon);
				withMon.show ();
			}

		}
		else if (obj == delRec || obj == del || obj == btnDel) {

			boolean b = openChildWindow ("Delete Account Holder");
			if (b == false) {
				DeleteCustomer delCus = new DeleteCustomer ();
				desktop.add (delCus);
				delCus.show ();
			}

		}
		else if (obj == search || obj == find || obj == btnSrch) {

			boolean b = openChildWindow ("Search Customer [By No.]");
			if (b == false) {
				FindAccount fndAcc = new FindAccount ();
				desktop.add (fndAcc);
				fndAcc.show ();
			}

		}
		else if (obj == searchName) {

			boolean b = openChildWindow ("Search Customer [By Name]");
			if (b == false) {
				FindName fndNm = new FindName ();
				desktop.add (fndNm);
				fndNm.show ();
			}

		}
		else if (obj == oneByOne) {

			boolean b = openChildWindow ("View Account Holders");
			if (b == false) {
				ViewOne vwOne = new ViewOne ();
				desktop.add (vwOne);
				vwOne.show ();
			}

		}
		else if (obj == allCustomer || obj == all) {

			boolean b = openChildWindow ("View All Account Holders");
			if (b == false) {
				ViewCustomer viewCus = new ViewCustomer ();
				desktop.add (viewCus);
				viewCus.show ();
			}

		}
		else if (obj == change) {

			Color cl = new Color (153, 153, 204);
			cl = JColorChooser.showDialog (this, "Choose Background Color", cl);
			if (cl == null) { }
			else {
				desktop.setBackground (cl);
				desktop.repaint ();
			}

		}
		else if (obj == close) {

			try {
				desktop.getSelectedFrame().setClosed(true);
			}
			catch (Exception CloseExc) { }

		}
		else if (obj == closeAll) {

			JInternalFrame Frames[] = desktop.getAllFrames (); //Getting all Open Frames.
			for(int getFrameLoop = 0; getFrameLoop < Frames.length; getFrameLoop++) {
				try {
	 				Frames[getFrameLoop].setClosed (true); //Close the frame.
				} 
				catch (Exception CloseExc) { }	//if we can't close it then we have a problem.
			}

		}
		else if (obj == content || obj == btnHelp) {

			boolean b = openChildWindow ("BankSystem Help");
			if (b == false) {
				BankHelp hlpBank = new BankHelp ("BankSystem Help", "Help/Bank.htm");
				desktop.add (hlpBank);
				hlpBank.show ();
			}

		}
		else if (obj == keyHelp || obj == btnKey) {

			boolean b = openChildWindow ("BankSystem Keys");
			if (b == false) {
				BankHelp hlpKey = new BankHelp ("BankSystem Keys", "Help/Keys.htm");
				desktop.add (hlpKey);
				hlpKey.show ();
			}

		}
		else if (obj == about) {

			String msg = "BankSystem [Pvt] Limited.\n\n" + "Created & Designed By:\n" + 
				"Muhammad Wasif Javed\n\n" + "E-mail me:\n wasi_javed@hotmail.com";
			JOptionPane.showMessageDialog (this, msg, "About BankSystem", JOptionPane.PLAIN_MESSAGE);

		}

	}

	//Function Perform By LookAndFeel Menu.

	public void itemStateChanged (ItemEvent e) {

		for( int i = 0; i < radio.length; i++ )
			if(radio[i].isSelected()) {
				changeLookAndFeel (i);
			}

	}	

	//Function For Closing the Program.

	private void quitApp () {

		try {
			//Show a Confirmation Dialog.
		    	int reply = JOptionPane.showConfirmDialog (this,
					"Are you really want to exit\nFrom BankSystem?",
					"BankSystem - Exit", JOptionPane.YES_NO_OPTION, JOptionPane.PLAIN_MESSAGE);
			//Check the User Selection.
			if (reply == JOptionPane.YES_OPTION) {
				setVisible (false);	//Hide the Frame.
				dispose();            	//Free the System Resources.
				System.out.println ("Thanks for Using BankSystem\nAuthor - Muhammad Wasif Javed");
				System.exit (0);        //Close the Application.
			}
			else if (reply == JOptionPane.NO_OPTION) {
				setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
			}
		} 

		catch (Exception e) {}

	}

	//Function for Changing the Program's Look.

	public void changeLookAndFeel (int val) {

		try {
			UIManager.setLookAndFeel (looks[val].getClassName());
			SwingUtilities.updateComponentTreeUI (this);
		}
		catch (Exception e) { }

	}

	//Loop Through All the Opened JInternalFrame to Perform the Task.

	private boolean openChildWindow (String title) {

		JInternalFrame[] childs = desktop.getAllFrames ();
		for (int i = 0; i < childs.length; i++) {
			if (childs[i].getTitle().equalsIgnoreCase (title)) {
				childs[i].show ();
				return true;
			}
		}
		return false;

	}

	//Following Functions use for Printing Records & Report of BankSystem.

	void getAccountNo () {

		String printing;
		rows = 0;
		boolean b = populateArray ();
		if (b == false) { }
		else {
			try {
				printing = JOptionPane.showInputDialog (this, "Enter Account No. to Print Customer Balance.\n" +
				"(Tip: Account No. Contains only Digits)", "BankSystem - PrintRecord", JOptionPane.PLAIN_MESSAGE);
				if (printing == null) { }
				if (printing.equals ("")) {
					JOptionPane.showMessageDialog (this, "Provide Account No. to Print.",
						 "BankSystem - EmptyField", JOptionPane.PLAIN_MESSAGE);
					getAccountNo ();
				}
				else {
					findRec (printing);
				}
			}
			catch (Exception e) { }
		}

	}

	//Function use to load all Records from File when Application Execute.

	boolean populateArray () {

		boolean b = false;
		try {
			fis = new FileInputStream ("Bank.dat");
			dis = new DataInputStream (fis);
			//Loop to Populate the Array.
			while (true) {
				for (int i = 0; i < 6; i++) {
					records[rows][i] = dis.readUTF ();
				}
				rows++;
			}
		}
		catch (Exception ex) {
			total = rows;
			if (total == 0) {
				JOptionPane.showMessageDialog (null, "Records File is Empty.\nEnter Records First to Display.",
					 "BankSystem - EmptyFile", JOptionPane.PLAIN_MESSAGE);
				b = false;
			}
			else {
				b = true;
				try {
					dis.close();
					fis.close();
				}
				catch (Exception exp) { }
			}
		}
		return b;

	}

	//Function use to Find Record by Matching the Contents of Records Array with InputBox.

	void findRec (String rec) {

		boolean found = false;
		for (int x = 0; x < total; x++) {
			if (records[x][0].equals (rec)) {
				found = true;
				printRecord (makeRecordPrint (x));
				break;
			}
		}
		if (found == false) {
			JOptionPane.showMessageDialog (this, "Account No. " + rec + " doesn't Exist.",
					 "BankSystem - WrongNo", JOptionPane.PLAIN_MESSAGE);
			getAccountNo ();
		}

	}

	//Function use to make Current Record ready for Print.

	String makeRecordPrint (int rec) {

		String data;
		String data0 = "               BankSystem [Pvt] Limited.               \n";	//Page Title.
		String data1 = "               Customer Balance Report.              \n\n";	//Page Header.
		String data2 = "  Account No.:       " + records[rec][0] + "\n";
		String data3 = "  Customer Name:     " + records[rec][1] + "\n";
		String data4 = "  Last Transaction:  " + records[rec][2] + ", " + records[rec][3] + ", " + records[rec][4] + "\n";
		String data5 = "  Current Balance:   " + records[rec][5] + "\n\n";
		String data6 = "          Copyright ?2003 Muhammad Wasif Javed.\n";	//Page Footer.
		String sep0 = " -----------------------------------------------------------\n";
		String sep1 = " -----------------------------------------------------------\n";
		String sep2 = " -----------------------------------------------------------\n";
		String sep3 = " -----------------------------------------------------------\n";
		String sep4 = " -----------------------------------------------------------\n\n";

		data = data0 + sep0 + data1 + data2 + sep1 + data3 + sep2 + data4 + sep3 + data5 + sep4 + data6;
		return data;

	}

	//Function use to Print the Current Record.

	void printRecord (String rec) {

		StringReader sr = new StringReader (rec);
		LineNumberReader lnr = new LineNumberReader (sr);
		Font typeface = new Font ("Times New Roman", Font.PLAIN, 12);
		Properties p = new Properties ();
		PrintJob pJob = getToolkit().getPrintJob (this, "Print Customer Balance Report", p);

		if (pJob != null) {
			Graphics gr = pJob.getGraphics ();
			if (gr != null) {
				FontMetrics fm = gr.getFontMetrics (typeface);
				int margin = 20;
				int pageHeight = pJob.getPageDimension().height - margin;
    				int fontHeight = fm.getHeight();
	    			int fontDescent = fm.getDescent();
    				int curHeight = margin;
				String nextLine;
				gr.setFont (typeface);

				try {
					do {
						nextLine = lnr.readLine ();
						if (nextLine != null) {         
							if ((curHeight + fontHeight) > pageHeight) {	//New Page.
								gr.dispose();
								gr = pJob.getGraphics ();
								curHeight = margin;
							}							
							curHeight += fontHeight;
							if (gr != null) {
								gr.setFont (typeface);
								gr.drawString (nextLine, margin, curHeight - fontDescent);
							}
						}
					}
					while (nextLine != null);					
				}
				catch (EOFException eof) { }
				catch (Throwable t) { }
			}
			gr.dispose();
		}
		if (pJob != null)
			pJob.end ();
	}

}

⌨️ 快捷键说明

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