0% found this document useful (0 votes)
1 views

trainingjava

Uploaded by

ritin3098
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views

trainingjava

Uploaded by

ritin3098
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 79

INTRODUCTION TO JAVA

UNIT STRUCTURE

1.1Java

1.2 Basic concepts of OOPs

1.3 Java History

1.4 Java Feature

1.5 Java Virtual Machine

1.6 Java Environment

1.7 SWING

1.8 JDBC

1.1 Java:

Java is a high-level, third generation programming language, like C, FORTRAN, Smalltalk, Perl,
and many others. You can use Java to write computer applications that play games, store data or
do any of the thousands of other things computer software can do. Compared to other
programming languages, Java is most similar to C. However although Java shares much of C's
syntax, it is not C. Knowing how to program in C or, better yet, C++, will certainly help you to
learn Java more quickly, but you don't need to know C to learn Java. A Java compiler won't
compile C code, and most large C programs need to be changed substantially before they can
become Java programs. What's most special about Java in relation to other programming
languages is that it lets you write special programs called applets that can be downloaded from
the Internet and played safely within a web browser. Java language is called as an Object-
Oriented Programming language and before beginning for Java, we have to learn the concept of
OOPs (Object-Oriented Programming).

1.2 Basic Concept of OOP (Object-Oriented Programming):

There are some basic concepts of object oriented programming as follows:

Bank Management System by RAVISHER SINGH BRAR (B.Tech (CSE), Roll Number 220280091)
1.2.1 Object

1.2.2 Class

1.2.3 Data abstraction

1.2.4 Data encapsulation

1.2.5 Inheritance

1.2.6Polymorphism

1.2.7 Dynamic binding

1.2.1 Object

Objects are important runtime entities in object oriented method. They may characterize a
location, a bank account, and a table of data or any entry that the program must handle.

Each object holds data and code to operate the data. Object can interact without having to
identify the details of each other‘s data or code. It is sufficient to identify the type of message
received and the type of reply returned by the objects.

1.2.2 Classes

A class is a set of objects with similar properties (attributes), common behaviour (operations),
and common link to other objects. The complete set of data and code of an object can be made a
user defined data type with the help of class.
The objects are variable of type class. A class is a collection of objects of similar type.
Classes are user defined data types and work like the build in type of the programming language.
Once the class has been defined, we can make any number of objects belonging to that class.
Each object is related with the data of type class with which they are formed.

As we learned that, the classification of objects into various classes is based on its
properties (States) and behavior (methods). Classes are used to distinguish are type of object
from another. The important thing about the class is to identify the properties and procedures and
applicability to its instances.

Bank Management System by RAVISHER SINGH BRAR (B.Tech (CSE), Roll Number 220280091)
1.2.3 Data Abstraction
Data abstraction refers to the act of representing important description without including the
background details or explanations.
Classes use the concept of abstraction and are defined as a list of abstract attributes such
as size, cost and functions operate on these attributes. They summarize all the important
properties of the objects that are to be created.
Classes use the concepts of data abstraction and it is called as Abstract Data Type (ADT).
1.2.4 Data Encapsulation
Data Encapsulation means wrapping of data and functions into a single unit (i.e. class). It is most
useful feature of class. The data is not easy to get to the outside world and only those functions
which are enclosed in the class can access it.
These functions provide the boundary between Object‘s data and program. This insulation of
data from direct access by the program is called as Data hiding.

1.2.5 Inheritance

Inheritance is the process by which objects of one class can get the properties of objects of
another class. Inheritance means one class of objects inherits the data and behaviours from
another class. Inheritance maintains the hierarchical classification in which a class inherits from
its parents.

Inheritance provides the important feature of OOP that is reusability. That means we can include
additional characteristics to an existing class without modification. This is possible deriving a
new class from existing one.

In other words, it is property of object-oriented systems that allow objects to be built


from other objects. Inheritance allows openly taking help of the commonality of objects when
constructing new classes. Inheritance is a relationship between classes where one class is the
parent class of another (derived) class. The derived class holds the properties and behaviour of
base class in addition to the properties and behaviour of derived class.

1.2.6 Polymorphism

Bank Management System by RAVISHER SINGH BRAR (B.Tech (CSE), Roll Number 220280091)
(Poly means ―many‖ and morph means ―form‖). Polymorphism means the ability to take more
than one form. Polymorphism plays a main role in allocate objects having different internal
structures to share the same external interface. This means that a general class of operations may
be accessed in the same manner even though specific activities associated with each operation
may differ. Polymorphism is broadly used in implementing inheritance.

It means objects that can take on or assume many different forms. Polymorphism means that the
same operations may behave differently on different classes. Booch defines polymorphism as the
relationship of objects many different classes by some common super class. Polymorphism
allows us to write generic, reusable code more easily, because we can specify general
instructions and delegate the implementation detail to the objects involved.

1.2.7 Dynamic Binding

Binding refers to the linking of a procedure call to the code to be executed in response to the call.
Dynamic binding means that the code related with a given procedure call is not known until the
time of the call at run time. Dynamic binding is associated polymorphism and inheritance.

1.3 Java History:

Java is a general-purpose, object-oriented programming language developed by Sun


Microsystems of USA in 1991.Originally called Oak by James Gosling (one of the inventor of
the language). Java was invented for the development of software for consumer electronic
devices like TVs, tosters, etc. The main aim had to make java simple, portable and reliable. Java
Authors: James, Arthur Van, and others

Following table shows the year


and beginning of Java.
Progress
Year

1990 Sun decided to developed software that could be


used for electronic devices. And the project called
as Green Project head by James Gosling.

Bank Management System by RAVISHER SINGH BRAR (B.Tech (CSE), Roll Number 220280091)
1991 Announcement of a new language named ―Oak‖

1992 The team verified the application of their new


language to manage a list of home appliances using
a hand held device.

1993 The World Wide Web appeared on the Internet and


transformed the text-based interface to a graphical
rich environment.

1994 The team developed a new Web browser called


―Hot Java‖ to locate and run Applets.

1995 Oak was renamed to Java, as it did not survive


―legal‖ registration. Many companies such as
Netscape and Microsoft announced their support for
Java.

1996 Java language is now famous for Internet


programming as well as a general purpose OO
language.

1997 Sun releases Java Development Kit(JDK 1.1)

1998 Sun releases Software Development Kit (SDK 1.2)

1999 Sun releases Java 2 platform Standard Edition


(J2SE) and Enterprise Edition (J2EE).

2000 J2SE with SDK 1.3 was released.

2002 J2SE with SDK 1.4 was released.

2004 J2SE with JDK 5.0 was released.

1.4 Java Features:

Bank Management System by RAVISHER SINGH BRAR (B.Tech (CSE), Roll Number 220280091)
As we know that the Java is an object oriented programming language developed by Sun
Microsystems of USA in 1991. Java is first programming language which is not attached with
any particular hardware or operating system. Program developed in Java can be executed
anywhere and on any system.

Features of Java are as follows:

1.4.1 Compiled and Interpreted

1.4.2 Platform Independent and portable

1.4.3 Object- oriented

1.4.4 Robust and secure

1.4.5 Distributed

1.4.6 Familiar, simple and small

1.4.7 Multithreaded and Interactive

1.4.8 High performance

1.4.9 Dynamic and Extensible

1.4.1 Compiled and Interpreted

Basically a computer language is either compiled or interpreted. Java comes together both these
approach thus making Java a two-stage system.

Java compiler translates Java code to Bytecode instructions and Java Interpreter generate
machine code that can be directly executed by machine that is running the Java program.

1.4.2 Platform Independent and portable

Java supports the feature portability. Java programs can be easily moved from one
computer system to another and anywhere. Changes and upgrades in operating systems,
processors and system resources will not force any alteration in Java programs. This is reason

Bank Management System by RAVISHER SINGH BRAR (B.Tech (CSE), Roll Number 220280091)
why Java has become a trendy language for programming on Internet which interconnects
different kind of systems worldwide. Java certifies portability in two ways.

First way is, Java compiler generates the bytecode and that can be executed on any machine.
Second way is, size of primitive data types are machine independent.

1.4.3 Object- oriented

Java is truly object-oriented language. In Java, almost everything is an Object. All program
code and data exist in objects and classes. Java comes with an extensive set of classes; organize
in packages that can be used in program by Inheritance. The object model in Java is trouble-free
and easy to enlarge.

1.4.4 Robust and secure

Java is a most strong language which provides many securities to make certain reliable
code. It is design as garbage –collected language, which helps the programmers virtually from all
memory management problems. Java also includes the concept of exception handling, which
detain serious errors and reduces all kind of threat of crashing the system.

Security is an important feature of Java and this is the strong reason that programmer use
this language for programming on Internet.

The absence of pointers in Java ensures that programs cannot get right of entry to
memory location without proper approval.

1.4.5 Distributed

Java is called as Distributed language for construct applications on networks which can
contribute both data and programs. Java applications can open and access remote objects on
Internet easily. That means multiple programmers at multiple remote locations to work together
on single task.

1.4.6 Simple and small

Java is very small and simple language. Java does not use pointer and header files, goto
statements, etc. It eliminates operator overloading and multiple inheritance.

Bank Management System by RAVISHER SINGH BRAR (B.Tech (CSE), Roll Number 220280091)
1.4.7 Multithreaded and Interactive

Multithreaded means managing multiple tasks simultaneously. Java maintains


multithreaded programs. That means we need not wait for the application to complete one task
before starting next task. This feature is helpful for graphic applications.

1.4.8 High performance

Java performance is very extraordinary for an interpreted language, majorly due to the
use of intermediate bytecode. Java architecture is also designed to reduce overheads during
runtime. The incorporation of multithreading improves the execution speed of program.

1.4.9 Dynamic and Extensible

Java is also dynamic language. Java is capable of dynamically linking in new class,
libraries, methods and objects. Java can also establish the type of class through the query
building it possible to either dynamically link or abort the program, depending on the reply.

Java program is support functions written in other language such as C and C++, known as native
methods.

1.5 Java Virtual Machine:

As we know that all programming language compilers convert the source code to machine code.
Same job done by Java Compiler to run a Java program, but the difference is that Java compiler
convert the source code into Intermediate code is called as byte code. This machine is called the
Java Virtual machine and it exists only inside the computer memory.

Following figure shows the process of compilation.

Java Program Java Compiler Virtual Machine

Code Source Code Byte

Figure 1.1 Process of compilation

Bank Management System by RAVISHER SINGH BRAR (B.Tech (CSE), Roll Number 220280091)
The Virtual machine code is not machine specific. The machine specific code is generated. By
Java interpreter by acting as an intermediary between the virtual machine and real machines
shown below

Byte Code Java Interpreter Machine code

Machine Virtual machine Real

Figure 1.2 Virtual Machine and Real Machines

1.6 Java Environment:

Java environment includes a number of development tools, classes and methods. The
development tools are part of the system known as Java Development Kit (JDK) and the classes
and methods are part of the Java Standard Library (JSL), also known as the Application
Programming Interface (API).

Java Development kit (JDK) – The JDK comes with a set of tools that are used for developing
and running Java program. It includes:

1.6.1 Applet viewer (It is used for viewing the applet)

1.6.2 Javac (It is a Java Compiler)

1.6.3 Java (It is a java interpreter)

1.6.4 Javap (Java diassembler, which convert byte code into program description)

1.6.5 Javah (It is for java C header files)

1.6.6 Javadoc (It is for creating HTML document)

1.6.7 Jdb (It is Java debugger)

For compiling and running the program we have to use following commands:

a) Javac (Java compiler)

Bank Management System by RAVISHER SINGH BRAR (B.Tech (CSE), Roll Number 220280091)
In java, we can use any text editor for writing program and then save that program with ―.java‖
extension. Java compiler converts the source code or program in bytecode and interpreter convert
―.java‖ file in ―.class‖ file.

Syntax:

javac filename.java

If my filename is ―abc.java‖ then the syntax will be

javac abc.java

b) Java (Java Interpreter)

As we learn that, we can use any text editor for writing program and then save that program with
―.java‖ extension. Java compiler converts the source code or program in bytecode and
interpreter convert ―.java‖ file in ―.class‖ file.

Syntax:

java filename

If my filename is login.java then the syntax will be

java login

1.7 Swing:

Swing components facilitate efficient graphical user interface (GUI) development. These
components are a collection of lightweight visual components. Swing components contain a
replacement for the heavyweight AWT components as well as complex user-interface
components such as trees and tables.
Swing components contain a pluggable look and feel (PL&F). This allows all applications to run
with the native look and feel on different platforms. PL&F allows applications to have the same
behavior on various platforms. JFC contains operating systems neutral look and feel. Swing
components do not contain peers. Swing components allow mixing AWT heavyweight and
swing lightweight components in an application. The major difference between lightweight and

Bank Management System by RAVISHER SINGH BRAR (B.Tech (CSE), Roll Number 220280091)
heavyweight components is that lightweight components can have transparent pixels while
heavyweight components are always opaque. Lightweight components can be non-regular while
heavyweight components are always rectangular.

Swing components are JavaBean compliant. This allows components to be used easily in a Bean
aware applications building program. The root of the majority of the swing hierarchy is the
Jcomponent class. The class is an extension of the AWT container class.

Swing packages:

Some of the Swing packages are given below.

Javax.swing.plaf. Basic: Contains classes that define the default look and feel of swing
components.

Javax.swing.border: Contains border interface and their related interfaces.

Javax.swing. event: Define events specific to swing components.

Javax.swing.plaf.multi: Consist of multiplexing UI classes

Javax.swing.plaf: Consist of classes that provide swing components with pluggable look and feel
capabilities.

Javax.swing.table: Contains classes and interfaces specific to the swing table components

Javax.swing.text: Contains classes and interfaces for text manipulation components contained in
swing toolkit.

Javax.swing.tree: Contains classes that are used with the swing tree component

Javax.swing.undo: contains interfaces and classes required to implement the undo functionality.

1.8 JDBC:

JDBC stands for Java Database Connectivity. It is set of Java API‘s(application programming
interface) used for executing SQL statements. This API consists of a set of classes and interfaces
to enable programmers to write pure Java Database applications.

Bank Management System by RAVISHER SINGH BRAR (B.Tech (CSE), Roll Number 220280091)
JDBC is a software layer that allows developers to write real client –server projects in
Java. JDBC does not concern itself with specific DBMS functions. JDBC API defines how an
application opens a connection, communicates with a database, executes SQL statements, and
retrieves query result. Following fig. will illustrate the role of JDBC. JDBC is based on the
X/OPEN call level interface (CLI) for SQL.

Call Level Interface is a library of function calls that supports SQL statements. CLI
requires neither host variables nor other embedded SQL concepts that would make it less flexible
from a programmer‘s perspective. It is still possible, however, to maintain and use specific
functions of a database management system when accessing the database through a CLI.

Figure 1.3 JDBC

JDBC was designed to be very compact, simple interface focusing on the execution of
raw SQL statements and retrieving the results. The goal of creating JDBC is to create an
interface that keeps simple tasks, while ensuring the more difficult and uncommon tasks are at
least made possible.

The following are the characteristics of JDBC.

• It is a call-level SQL interface for java

• It does not restrict the type of queries passed to an underlying DBMS driver

• JDBC mechanism are simple to understand and use

Bank Management System by RAVISHER SINGH BRAR (B.Tech (CSE), Roll Number 220280091)
• It provides a java interface that stays consistent with the rest of the Java system

• JDBC may be implemented on top of common SQL level APIs.

Microsoft ODBC API offers connectivity to almost all databases on all platforms and is
the most widely used programming interface for accessing relational database. But ODBC
cannot be directly used with java programs due to various reasons enumerated in the JDBC vs.
ODBC section. Hence the need for JDBC came into existence.

It is possible to access various relational databases like Sybase, Oracle, Informix, Ingers,
using JDBC API. Using JDBC, we can write individual programs to connect to individual
database or one program that take care of connecting to the respective database.

How does JDBC WORK?

JDBC defines a set of API objects and methods to interact with the underlying database. A Java
program first opens a connection to the database, makes a statement object, passes SQL
statements to the underlying database management system (DBMS) through the statement object
and retrieve the results as well as information about the result set.

There are two types of interfaces – low –level interface and high-level interface. While high level
interfaces are user-friendly, low-level interfaces are not. JDBC is a low-level API interface, ie. it
used to invoke or call SQL commands directly. The required SQL statements are passed as
strings to Java methods.

Some of the current trend that is being developed to add more features to JDBC are embedded
SQL for java and direct mapping of relational database to java classes.

Embedded SQL enables mixing of java into SQL statements. These statements are translated into
JDBC calls using SQL Processor. In this type of direct mapping of relational database tables to
java, each row of the table becomes an instance of the class and each column value corresponds
to an attribute of that instance. Mapping is being provided that makes rows of multiple tables to
form a java class.

Details about JDBC

Bank Management System by RAVISHER SINGH BRAR (B.Tech (CSE), Roll Number 220280091)
The JDBC API is in the package java.sql it consists of 8 interfaces, 6 classes and 3 exceptions in
JDK1.1.

Interfaces:
• CallableStatement
• Connection
• DatabaseMetadata
• Driver
• PreparedStatement
• ResultSet
• ResultSetMetaData
• Statement
Classes:
• Date
• DriverManager
• DriverPropertyInfo
• Time
• Timestamp
• Types
Exceptions:

• DataTruncation
• SQLException
• SQLWarning

Bank Management System by RAVISHER SINGH BRAR (B.Tech (CSE), Roll Number 220280091)
Figure 1.4 JDBC DRIVER MODEL

Bank Management System by RAVISHER SINGH BRAR (B.Tech (CSE), Roll Number 220280091)
PROJECT DETAIL

3.1 Introduction

This is Project (software) which is very helpful for the employee who can save the records of our
Bank Management. Before this software employee maintains their records manually on files,
notebooks etc. but now he can do this type of work in this software. Software is Current Working
manually. Employee gave us requirements as per his needs.

3.1.1 Bank System:

• Create New Account


• Deposit Money
• Withdrawal Money
• Print Customer Balance
• Delete Accounts
• Find Customer by Account Number
• Find Customer by Customer Name
• View All Customer One by One
• View All Customer

3.4 Objective of Proposed System

After thoroughly analyzing the existing system, some objectives of the proposed system
have been set:

• Controlling redundancy in storing the same multiples times.

• Adequate validation checks for data accuracy.

• Prompt Easy and Specific retrieval of data.

• Flexibility of the system.

• Adequate security.

Bank Management System by RAVISHER SINGH BRAR (B.Tech (CSE), Roll Number 220280091)
• Application must be user friendly.

• Less manual work.

• Saving of time.

• Less paper consumption.

• Fast operations.

Bank Management System by RAVISHER SINGH BRAR (B.Tech (CSE), Roll Number 220280091)
SYSTEM REQUIREMENTS

4.1 Hardware Requirements

• Processor: Intel Dual Core 1.6 MHz or higher

• RAM: 512 MB or higher

• Hard Disk: 1 GB free or higher

4.2 Software Requirements

• Windows XP or Higher

• JDK 1.6 or higher (Front End)

• My SQL (Back End)

Bank Management System by RAVISHER SINGH BRAR (B.Tech (CSE), Roll Number 220280091)
SCREENSHOT

Main Page

Bank Management System by RAVISHER SINGH BRAR (B.Tech (CSE), Roll Number 220280091)
Creating new account

Bank Management System by RAVISHER SINGH BRAR (B.Tech (CSE), Roll Number 220280091)
Print records

Bank Management System by RAVISHER SINGH BRAR (B.Tech (CSE), Roll Number 220280091)
Deposit money

Bank Management System by RAVISHER SINGH BRAR (B.Tech (CSE), Roll Number 220280091)
Withdraw money

Bank Management System by RAVISHER SINGH BRAR (B.Tech (CSE), Roll Number 220280091)
Delete account

Bank Management System by RAVISHER SINGH BRAR (B.Tech (CSE), Roll Number 220280091)
Search customer by number

Bank Management System by RAVISHER SINGH BRAR (B.Tech (CSE), Roll Number 220280091)
Search customer by name

Bank Management System by RAVISHER SINGH BRAR (B.Tech (CSE), Roll Number 220280091)
View account holders one by one

Bank Management System by RAVISHER SINGH BRAR (B.Tech (CSE), Roll Number 220280091)
View all account holders

Bank Management System by RAVISHER SINGH BRAR (B.Tech (CSE), Roll Number 220280091)
CODING

import javax.swing.*;
import java.awt.*;
import java.net.URL;
import java.net.MalformedURLException;
import java.io.*;
import javax.swing.text.*;
import javax.swing.event.*;

public class BankHelp extends JInternalFrame {

public BankHelp (String title, String filename) {

// super(Title, Resizable, Closable, Maximizable, Iconifiable)


super (title, false, true, false, true);
setSize (500, 350);

HtmlPane html = new HtmlPane (filename);


setContentPane (html);

setVisible (true);

class HtmlPane extends JScrollPane implements HyperlinkListener {

JEditorPane html;

public HtmlPane(String filename) {

try {
File f = new File (filename);
String s = f.getAbsolutePath();
s = "file:"+s;
URL url = new URL(s);
html = new JEditorPane(s);
html.setEditable(false);
html.addHyperlinkListener(this);
JViewport vp = getViewport();
vp.add(html);
}

Bank Management System by RAVISHER SINGH BRAR (B.Tech (CSE), Roll Number 220280091)
catch (MalformedURLException e) {
System.out.println("Malformed URL: " + e);
}
catch (IOException e) {
System.out.println("IOException: " + e);
}

public void hyperlinkUpdate(HyperlinkEvent e) {

if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
linkActivated(e.getURL());
}
}

protected void linkActivated(URL u) {

Cursor c = html.getCursor();
Cursor waitCursor = Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR);
html.setCursor(waitCursor);
SwingUtilities.invokeLater(new PageLoader(u, c));

class PageLoader implements Runnable {

PageLoader(URL u, Cursor c) {

url = u;
cursor = c;

public void run() {

if (url == null) {
html.setCursor(cursor);
Container parent = html.getParent();
parent.repaint();
}
else {
Document doc = html.getDocument();
try {
html.setPage(url);
}

Bank Management System by RAVISHER SINGH BRAR (B.Tech (CSE), Roll Number 220280091)
catch (IOException ioe) {
html.setDocument(doc);
getToolkit().beep();
}
finally {
url = null;
SwingUtilities.invokeLater(this);
}
}

URL url;
Cursor cursor;

Bank Management System by RAVISHER SINGH BRAR (B.Tech (CSE), Roll Number 220280091)
NewAccount.java
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;

public class NewAccount extends JInternalFrame implements ActionListener {

private JPanel jpInfo = new JPanel();


private JLabel lbNo, lbName, lbDate, lbDeposit;
private JTextField txtNo, txtName, txtDeposit;
private JComboBox cboMonth, cboDay, cboYear;
private JButton btnSave, btnCancel;

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];

//String Type Array use to Save Records into File.


private String saves[][] = new String [500][6];

private FileInputStream fis;


private DataInputStream dis;

NewAccount () {

// super(Title, Resizable, Closable, Maximizable, Iconifiable)


super ("Create New Account", false, true, false, true);
setSize (335, 235);

jpInfo.setBounds (0, 0, 500, 115);


jpInfo.setLayout (null);

lbNo = new JLabel ("Account No:");


lbNo.setForeground (Color.black);
lbNo.setBounds (15, 20, 80, 25);
lbName = new JLabel ("Person Name:");
lbName.setForeground (Color.black);
lbName.setBounds (15, 55, 80, 25);
lbDate = new JLabel ("Deposit Date:");
lbDate.setForeground (Color.black);
lbDate.setBounds (15, 90, 80, 25);
lbDeposit = new JLabel ("Dep. Amount:");

Bank Management System by RAVISHER SINGH BRAR (B.Tech (CSE), Roll Number 220280091)
lbDeposit.setForeground (Color.black);
lbDeposit.setBounds (15, 125, 80, 25);

txtNo = new JTextField ();


txtNo.setHorizontalAlignment (JTextField.RIGHT);
txtNo.setBounds (105, 20, 205, 25);
txtName = new JTextField ();
txtName.setBounds (105, 55, 205, 25);
txtDeposit = new JTextField ();
txtDeposit.setHorizontalAlignment (JTextField.RIGHT);
txtDeposit.setBounds (105, 125, 205, 25);

//Restricting The User Input to only Numerics in Numeric TextBoxes.


txtNo.addKeyListener (new KeyAdapter() {
public void keyTyped (KeyEvent ke) {
char c = ke.getKeyChar ();
if (!((Character.isDigit (c) || (c ==
KeyEvent.VK_BACK_SPACE)))) {
getToolkit().beep ();
ke.consume ();
}
}
}
);
txtDeposit.addKeyListener (new KeyAdapter() {
public void keyTyped (KeyEvent ke) {
char c = ke.getKeyChar ();
if (!((Character.isDigit (c) || (c ==
KeyEvent.VK_BACK_SPACE)))) {
getToolkit().beep ();
ke.consume ();
}
}
}
);

//Creating Date Option.


String Months[] = {"January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"};
cboMonth = new JComboBox (Months);
cboDay = new JComboBox ();
cboYear = new JComboBox ();
for (int i = 1; i <= 31; i++) {
String days = "" + i;
cboDay.addItem (days);
}

Bank Management System by RAVISHER SINGH BRAR (B.Tech (CSE), Roll Number 220280091)
for (int i = 2017; i <= 2017; i++) {
String years = "" + i;
cboYear.addItem (years);
}

//Aligning The Date Option Controls.


cboMonth.setBounds (105, 90, 92, 25);
cboDay.setBounds (202, 90, 43, 25);
cboYear.setBounds (250, 90, 60, 25);

//Aligning The Buttons.


btnSave = new JButton ("Save");
btnSave.setBounds (20, 165, 120, 25);
btnSave.addActionListener (this);
btnCancel = new JButton ("Cancel");
btnCancel.setBounds (185, 165, 120, 25);
btnCancel.addActionListener (this);

//Adding the All the Controls to Panel.


jpInfo.add (lbNo);
jpInfo.add (txtNo);
jpInfo.add (lbName);
jpInfo.add (txtName);
jpInfo.add (lbDate);
jpInfo.add (cboMonth);
jpInfo.add (cboDay);
jpInfo.add (cboYear);
jpInfo.add (lbDeposit);
jpInfo.add (txtDeposit);
jpInfo.add (btnSave);
jpInfo.add (btnCancel);

//Adding Panel to Window.


getContentPane().add (jpInfo);

//In the End Showing the New Account Window.


setVisible (true);

//Function use By Buttons of Window to Perform Action as User Click Them.


public void actionPerformed (ActionEvent ae) {

Object obj = ae.getSource();

if (obj == btnSave) {

Bank Management System by RAVISHER SINGH BRAR (B.Tech (CSE), Roll Number 220280091)
if (txtNo.getText().equals("")) {
JOptionPane.showMessageDialog (this, "Please! Provide Id of
Customer.",
"BankSystem - EmptyField",
JOptionPane.PLAIN_MESSAGE);
txtNo.requestFocus();
}
else if (txtName.getText().equals("")) {
JOptionPane.showMessageDialog (this, "Please! Provide Name of
Customer.",
"BankSystem - EmptyField",
JOptionPane.PLAIN_MESSAGE);
txtName.requestFocus ();
}
else if (txtDeposit.getText().equals("")) {
JOptionPane.showMessageDialog (this, "Please! Provide Deposit
Amount.",
"BankSystem - EmptyField",
JOptionPane.PLAIN_MESSAGE);
txtDeposit.requestFocus ();
}
else {
populateArray (); //Load All Existing Records in Memory.
findRec (); //Finding if Account No. Already Exist or
Not.
}
}
if (obj == btnCancel) {
txtClear ();
setVisible (false);
dispose();
}

//Function use to load all Records from File when Application Execute.
void populateArray () {

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 ();
}

Bank Management System by RAVISHER SINGH BRAR (B.Tech (CSE), Roll Number 220280091)
rows++;
}
}
catch (Exception ex) {
total = rows;
if (total == 0) { }
else {
try {
dis.close();
fis.close();
}
catch (Exception exp) { }
}
}

//Function use to Find Record by Matching the Contents of Records Array with ID
TextBox.
void findRec () {

boolean found = false;


for (int x = 0; x < total; x++) {
if (records[x][0].equals (txtNo.getText())) {
found = true;
JOptionPane.showMessageDialog (this, "Account No. " +
txtNo.getText () + " is Already Exist.",
"BankSystem - WrongNo",
JOptionPane.PLAIN_MESSAGE);
txtClear ();
break;
}
}
if (found == false) {
saveArray ();
}

//Function use to add new Element to Array.


void saveArray () {

saves[count][0] = txtNo.getText ();


saves[count][1] = txtName.getText ();
saves[count][2] = "" + cboMonth.getSelectedItem ();
saves[count][3] = "" + cboDay.getSelectedItem ();

Bank Management System by RAVISHER SINGH BRAR (B.Tech (CSE), Roll Number 220280091)
saves[count][4] = "" + cboYear.getSelectedItem ();
saves[count][5] = txtDeposit.getText ();
saveFile (); //Save This Array to File.
count++;

//Function use to Save new Record to the File.


void saveFile () {

try {
FileOutputStream fos = new FileOutputStream ("Bank.dat", true);
DataOutputStream dos = new DataOutputStream (fos);
dos.writeUTF (saves[count][0]);
dos.writeUTF (saves[count][1]);
dos.writeUTF (saves[count][2]);
dos.writeUTF (saves[count][3]);
dos.writeUTF (saves[count][4]);
dos.writeUTF (saves[count][5]);
JOptionPane.showMessageDialog (this, "The Record has been Saved
Successfully",
"BankSystem - Record Saved",
JOptionPane.PLAIN_MESSAGE);
txtClear ();
dos.close();
fos.close();
}
catch (IOException ioe) {
JOptionPane.showMessageDialog (this, "There are Some Problem with
File",
"BankSystem - Problem",
JOptionPane.PLAIN_MESSAGE);
}

//Function use to Clear all TextFields of Window.


void txtClear () {

txtNo.setText ("");
txtName.setText ("");
txtDeposit.setText ("");
txtNo.requestFocus ();

}
}

Bank Management System by RAVISHER SINGH BRAR (B.Tech (CSE), Roll Number 220280091)
DepositMoney
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;

public class DepositMoney extends JInternalFrame implements ActionListener {

private JPanel jpDep = new JPanel();


private JLabel lbNo, lbName, lbDate, lbDeposit;
private JTextField txtNo, txtName, txtDeposit;
private JComboBox cboMonth, cboDay, cboYear;
private JButton btnSave, btnCancel;

private int recCount = 0;


private int rows = 0;
private int total = 0;
private int curr;
private int deposit;

//String Type Array use to Load Records From File.


private String records[][] = new String [500][6];

private FileInputStream fis;


private DataInputStream dis;

DepositMoney () {

// super(Title, Resizable, Closable, Maximizable, Iconifiable)


super ("Deposit Money", false, true, false, true);
setSize (335, 235);

jpDep.setLayout (null);

lbNo = new JLabel ("Account No:");


lbNo.setForeground (Color.black);
lbNo.setBounds (15, 20, 80, 25);
lbName = new JLabel ("Person Name:");
lbName.setForeground (Color.black);
lbName.setBounds (15, 55, 80, 25);
lbDate = new JLabel ("Deposit Date:");
lbDate.setForeground (Color.black);
lbDate.setBounds (15, 90, 80, 25);
lbDeposit = new JLabel ("Dep. Amount:");
lbDeposit.setForeground (Color.black);
lbDeposit.setBounds (15, 125, 80, 25);

Bank Management System by RAVISHER SINGH BRAR (B.Tech (CSE), Roll Number 220280091)
txtNo = new JTextField ();
txtNo.setHorizontalAlignment (JTextField.RIGHT);
txtNo.setBounds (105, 20, 205, 25);
txtName = new JTextField ();
txtName.setEnabled (false);
txtName.setBounds (105, 55, 205, 25);
txtDeposit = new JTextField ();
txtDeposit.setHorizontalAlignment (JTextField.RIGHT);
txtDeposit.setBounds (105, 125, 205, 25);

//Creating Date Option.


String Months[] = {"January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"};
cboMonth = new JComboBox (Months);
cboDay = new JComboBox ();
cboYear = new JComboBox ();
for (int i = 1; i <= 31; i++) {
String days = "" + i;
cboDay.addItem (days);
}
for (int i = 2017; i <= 2017; i++) {
String years = "" + i;
cboYear.addItem (years);
}

//Aligning The Date Option Controls.


cboMonth.setBounds (105, 90, 92, 25);
cboDay.setBounds (202, 90, 43, 25);
cboYear.setBounds (250, 90, 60, 25);

//Aligning The Buttons.


btnSave = new JButton ("Save");
btnSave.setBounds (20, 165, 120, 25);
btnSave.addActionListener (this);
btnCancel = new JButton ("Cancel");
btnCancel.setBounds (185, 165, 120, 25);
btnCancel.addActionListener (this);

//Restricting The User Input to only Numerics in Numeric TextBoxes.


txtNo.addKeyListener (new KeyAdapter() {
public void keyTyped (KeyEvent ke) {
char c = ke.getKeyChar ();
if (!((Character.isDigit (c) || (c ==
KeyEvent.VK_BACK_SPACE)))) {
getToolkit().beep ();

Bank Management System by RAVISHER SINGH BRAR (B.Tech (CSE), Roll Number 220280091)
ke.consume ();
}
}
}
);
txtDeposit.addKeyListener (new KeyAdapter() {
public void keyTyped (KeyEvent ke) {
char c = ke.getKeyChar ();
if (!((Character.isDigit (c) || (c ==
KeyEvent.VK_BACK_SPACE)))) {
getToolkit().beep ();
ke.consume ();
}
}
}
);
//Checking the Accunt No. Provided By User on Lost Focus of the TextBox.
txtNo.addFocusListener (new FocusListener () {
public void focusGained (FocusEvent e) { }
public void focusLost (FocusEvent fe) {
if (txtNo.getText().equals ("")) { }
else {
rows = 0;
populateArray (); //Load All Existing Records in
Memory.
findRec (); //Finding if Account No. Already
Exist or Not.
}
}
}
);

//Adding the All the Controls to Panel.


jpDep.add (lbNo);
jpDep.add (txtNo);
jpDep.add (lbName);
jpDep.add (txtName);
jpDep.add (lbDate);
jpDep.add (cboMonth);
jpDep.add (cboDay);
jpDep.add (cboYear);
jpDep.add (lbDeposit);
jpDep.add (txtDeposit);
jpDep.add (btnSave);
jpDep.add (btnCancel);

Bank Management System by RAVISHER SINGH BRAR (B.Tech (CSE), Roll Number 220280091)
//Adding Panel to Window.
getContentPane().add (jpDep);

populateArray (); //Load All Existing Records in Memory.

//In the End Showing the New Account Window.


setVisible (true);

//Function use By Buttons of Window to Perform Action as User Click Them.


public void actionPerformed (ActionEvent ae) {

Object obj = ae.getSource();

if (obj == btnSave) {
if (txtNo.getText().equals("")) {
JOptionPane.showMessageDialog (this, "Please! Provide Id of
Customer.",
"BankSystem - EmptyField",
JOptionPane.PLAIN_MESSAGE);
txtNo.requestFocus();
}
else if (txtDeposit.getText().equals("")) {
JOptionPane.showMessageDialog (this, "Please! Provide Deposit
Amount.",
"BankSystem - EmptyField",
JOptionPane.PLAIN_MESSAGE);
txtDeposit.requestFocus ();
}
else {
editRec (); //Update the Contents of Array.
}
}
if (obj == btnCancel) {
txtClear ();
setVisible (false);
dispose();
}

//Function use to load all Records from File when Application Execute.
void populateArray () {

try {

Bank Management System by RAVISHER SINGH BRAR (B.Tech (CSE), Roll Number 220280091)
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);
btnEnable ();
}
else {
try {
dis.close();
fis.close();
}
catch (Exception exp) { }
}
}

//Function use to Find Record by Matching the Contents of Records Array with ID
TextBox.
void findRec () {

boolean found = false;


for (int x = 0; x < total; x++) {
if (records[x][0].equals (txtNo.getText())) {
found = true;
showRec (x);
break;
}
}
if (found == false) {
String str = txtNo.getText ();
txtClear ();

Bank Management System by RAVISHER SINGH BRAR (B.Tech (CSE), Roll Number 220280091)
JOptionPane.showMessageDialog (this, "Account No. " + str + " doesn't
Exist.",
"BankSystem - WrongNo",
JOptionPane.PLAIN_MESSAGE);
}

//Function which display Record from Array onto the Form.


public void showRec (int intRec) {

txtNo.setText (records[intRec][0]);
txtName.setText (records[intRec][1]);
curr = Integer.parseInt (records[intRec][5]);
recCount = intRec;

//Function use to Clear all TextFields of Window.


void txtClear () {

txtNo.setText ("");
txtName.setText ("");
txtDeposit.setText ("");
txtNo.requestFocus ();

//Function use to Edit an Element's Value of the Array.


public void editRec () {

deposit = Integer.parseInt (txtDeposit.getText ());


records[recCount][0] = txtNo.getText ();
records[recCount][1] = txtName.getText ();
records[recCount][2] = "" + cboMonth.getSelectedItem ();
records[recCount][3] = "" + cboDay.getSelectedItem ();
records[recCount][4] = "" + cboYear.getSelectedItem ();
records[recCount][5] = "" + (curr + deposit);
editFile (); //Save This Array to File.

//Function use to Save Records to File After editing the Record of User Choice.
public void editFile () {

try {

Bank Management System by RAVISHER SINGH BRAR (B.Tech (CSE), Roll Number 220280091)
FileOutputStream fos = new FileOutputStream ("Bank.dat");
DataOutputStream dos = new DataOutputStream (fos);
if (records != null) {
for (int i = 0; i < total; i++) {
for (int c = 0; c < 6; c++) {
dos.writeUTF (records[i][c]);
if (records[i][c] == null) break;
}
}
JOptionPane.showMessageDialog (this, "The File is Updated
Successfully",
"BankSystem - Record Saved",
JOptionPane.PLAIN_MESSAGE);
txtClear ();
dos.close();
fos.close();
}
}
catch (IOException ioe) {
JOptionPane.showMessageDialog (this, "There are Some Problem with
File",
"BankSystem - Problem",
JOptionPane.PLAIN_MESSAGE);
}

//Function use to Lock all Buttons of Window.


void btnEnable () {

txtNo.setEnabled (false);
cboMonth.setEnabled (false);
cboDay.setEnabled (false);
cboYear.setEnabled (false);
txtDeposit.setEnabled (false);
btnSave.setEnabled (false);

Bank Management System by RAVISHER SINGH BRAR (B.Tech (CSE), Roll Number 220280091)
WithdrawMoney.java
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;

public class WithdrawMoney extends JInternalFrame implements ActionListener {

private JPanel jpWith = new JPanel();


private JLabel lbNo, lbName, lbDate, lbWithdraw;
private JTextField txtNo, txtName, txtWithdraw;
private JComboBox cboMonth, cboDay, cboYear;
private JButton btnSave, btnCancel;

private int recCount = 0;


private int rows = 0;
private int total = 0;
private int curr;
private int withdraw;

//String Type Array use to Load Records From File.


private String records[][] = new String [500][6];

private FileInputStream fis;


private DataInputStream dis;

WithdrawMoney () {

// super(Title, Resizable, Closable, Maximizable, Iconifiable)


super ("Withdraw Money", false, true, false, true);
setSize (335, 235);

jpWith.setLayout (null);

lbNo = new JLabel ("Account No:");


lbNo.setForeground (Color.black);
lbNo.setBounds (15, 20, 80, 25);
lbName = new JLabel ("Person Name:");
lbName.setForeground (Color.black);
lbName.setBounds (15, 55, 80, 25);
lbDate = new JLabel ("With. Date:");
lbDate.setForeground (Color.black);
lbDate.setBounds (15, 90, 80, 25);
lbWithdraw = new JLabel ("With. Amount:");
lbWithdraw.setForeground (Color.black);
lbWithdraw.setBounds (15, 125, 80, 25);

Bank Management System by RAVISHER SINGH BRAR (B.Tech (CSE), Roll Number 220280091)
txtNo = new JTextField ();
txtNo.setHorizontalAlignment (JTextField.RIGHT);
//Checking the Accunt No. Provided By User on Lost Focus of the TextBox.
txtNo.addFocusListener (new FocusListener () {
public void focusGained (FocusEvent e) { }
public void focusLost (FocusEvent fe) {
if (txtNo.getText().equals ("")) { }
else {
rows = 0;
populateArray (); //Load All Existing Records in
Memory.
findRec (); //Finding if Account No. Already
Exist or Not.
}
}
}
);
txtNo.setBounds (105, 20, 205, 25);

txtName = new JTextField ();


txtName.setEnabled (false);
txtName.setBounds (105, 55, 205, 25);
txtWithdraw = new JTextField ();
txtWithdraw.setHorizontalAlignment (JTextField.RIGHT);
txtWithdraw.setBounds (105, 125, 205, 25);

//Restricting The User Input to only Numerics in Numeric TextBoxes.


txtNo.addKeyListener (new KeyAdapter() {
public void keyTyped (KeyEvent ke) {
char c = ke.getKeyChar ();
if (!((Character.isDigit (c) || (c ==
KeyEvent.VK_BACK_SPACE)))) {
getToolkit().beep ();
ke.consume ();
}
}
}
);
txtWithdraw.addKeyListener (new KeyAdapter() {
public void keyTyped (KeyEvent ke) {
char c = ke.getKeyChar ();
if (!((Character.isDigit (c) || (c ==
KeyEvent.VK_BACK_SPACE)))) {
getToolkit().beep ();
ke.consume ();

Bank Management System by RAVISHER SINGH BRAR (B.Tech (CSE), Roll Number 220280091)
}
}
}
);

//Creating Date Option.


String Months[] = {"January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"};
cboMonth = new JComboBox (Months);
cboDay = new JComboBox ();
cboYear = new JComboBox ();
for (int i = 1; i <= 31; i++) {
String days = "" + i;
cboDay.addItem (days);
}
for (int i = 2017; i <= 2017; i++) {
String years = "" + i;
cboYear.addItem (years);
}

//Aligning The Date Option Controls.


cboMonth.setBounds (105, 90, 92, 25);
cboDay.setBounds (202, 90, 43, 25);
cboYear.setBounds (250, 90, 60, 25);

//Aligning The Buttons.


btnSave = new JButton ("Save");
btnSave.setBounds (20, 165, 120, 25);
btnSave.addActionListener (this);
btnCancel = new JButton ("Cancel");
btnCancel.setBounds (185, 165, 120, 25);
btnCancel.addActionListener (this);

//Adding the All the Controls to Panel.


jpWith.add (lbNo);
jpWith.add (txtNo);
jpWith.add (lbName);
jpWith.add (txtName);
jpWith.add (lbDate);
jpWith.add (cboMonth);
jpWith.add (cboDay);
jpWith.add (cboYear);
jpWith.add (lbWithdraw);
jpWith.add (txtWithdraw);
jpWith.add (btnSave);
jpWith.add (btnCancel);

Bank Management System by RAVISHER SINGH BRAR (B.Tech (CSE), Roll Number 220280091)
//Adding Panel to Window.
getContentPane().add (jpWith);

populateArray (); //Load All Existing Records in Memory.

//In the End Showing the New Account Window.


setVisible (true);

//Function use By Buttons of Window to Perform Action as User Click Them.


public void actionPerformed (ActionEvent ae) {

Object obj = ae.getSource();

if (obj == btnSave) {
if (txtNo.getText().equals("")) {
JOptionPane.showMessageDialog (this, "Please! Provide Id of
Customer.",
"BankSystem - EmptyField",
JOptionPane.PLAIN_MESSAGE);
txtNo.requestFocus();
}
else if (txtWithdraw.getText().equals("")) {
JOptionPane.showMessageDialog (this, "Please! Provide
Withdraw Amount.",
"BankSystem - EmptyField",
JOptionPane.PLAIN_MESSAGE);
txtWithdraw.requestFocus ();
}
else {
withdraw = Integer.parseInt (txtWithdraw.getText ());
if (curr == 0) {
JOptionPane.showMessageDialog (this, txtName.getText ()
+ " doesn't have any Amount in Balance.",
"BankSystem - EmptyAccount",
JOptionPane.PLAIN_MESSAGE);
txtClear ();
}
else if (withdraw > curr) {
JOptionPane.showMessageDialog (this, "Withdraw
Amount can't greater than Actual Balance.",
"BankSystem - Large Amount",
JOptionPane.PLAIN_MESSAGE);
txtWithdraw.setText ("");

Bank Management System by RAVISHER SINGH BRAR (B.Tech (CSE), Roll Number 220280091)
txtWithdraw.requestFocus ();
}
else {
editRec (); //Update the Contents of Array.
}
}
}
if (obj == btnCancel) {
txtClear ();
setVisible (false);
dispose();
}

//Function use to load all Records from File when Application Execute.
void populateArray () {

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);
btnEnable ();
}
else {
try {
dis.close();
fis.close();
}
catch (Exception exp) { }
}
}

Bank Management System by RAVISHER SINGH BRAR (B.Tech (CSE), Roll Number 220280091)
}

//Function use to Find Record by Matching the Contents of Records Array with ID
TextBox.
void findRec () {

boolean found = false;


for (int x = 0; x < total; x++) {
if (records[x][0].equals (txtNo.getText())) {
found = true;
showRec (x);
break;
}
}
if (found == false) {
String str = txtNo.getText ();
txtClear ();
JOptionPane.showMessageDialog (this, "Account No. " + str + " doesn't
Exist.",
"BankSystem - WrongNo",
JOptionPane.PLAIN_MESSAGE);
}

//Function which display Record from Array onto the Form.


public void showRec (int intRec) {

txtNo.setText (records[intRec][0]);
txtName.setText (records[intRec][1]);
curr = Integer.parseInt (records[intRec][5]);
recCount = intRec;

//Function use to Clear all TextFields of Window.


void txtClear () {

txtNo.setText ("");
txtName.setText ("");
txtWithdraw.setText ("");
txtNo.requestFocus ();

Bank Management System by RAVISHER SINGH BRAR (B.Tech (CSE), Roll Number 220280091)
//Function use to Edit an Element's Value of the Array.
public void editRec () {

records[recCount][0] = txtNo.getText ();


records[recCount][1] = txtName.getText ();
records[recCount][2] = "" + cboMonth.getSelectedItem ();
records[recCount][3] = "" + cboDay.getSelectedItem ();
records[recCount][4] = "" + cboYear.getSelectedItem ();
records[recCount][5] = "" + (curr - withdraw);
editFile (); //Save This Array to File.

//Function use to Save Records to File After editing the Record of User Choice.
public void editFile () {

try {
FileOutputStream fos = new FileOutputStream ("Bank.dat");
DataOutputStream dos = new DataOutputStream (fos);
if (records != null) {
for (int i = 0; i < total; i++) {
for (int c = 0; c < 6; c++) {
dos.writeUTF (records[i][c]);
if (records[i][c] == null) break;
}
}
JOptionPane.showMessageDialog (this, "The File is Updated
Successfully",
"BankSystem - Record Saved",
JOptionPane.PLAIN_MESSAGE);
txtClear ();
dos.close();
fos.close();
}
}
catch (IOException ioe) {
JOptionPane.showMessageDialog (this, "There are Some Problem with
File",
"BankSystem - Problem",
JOptionPane.PLAIN_MESSAGE);
}

//Function use to Lock all Buttons of Window.


void btnEnable () {

Bank Management System by RAVISHER SINGH BRAR (B.Tech (CSE), Roll Number 220280091)
txtNo.setEnabled (false);
cboMonth.setEnabled (false);
cboDay.setEnabled (false);
cboYear.setEnabled (false);
txtWithdraw.setEnabled (false);
btnSave.setEnabled (false);

Bank Management System by RAVISHER SINGH BRAR (B.Tech (CSE), Roll Number 220280091)
FindAccount.java
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;

public class FindAccount extends JInternalFrame implements ActionListener {

private JPanel jpFind = new JPanel();


private JLabel lbNo, lbName, lbDate, lbBal;
private JTextField txtNo, txtName, txtDate, txtBal;
private JButton btnFind, btnCancel;

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];

private FileInputStream fis;


private DataInputStream dis;

FindAccount () {

//super(Title, Resizable, Closable, Maximizable, Iconifiable)


super ("Search Customer [By No.]", false, true, false, true);
setSize (350, 235);

jpFind.setLayout (null);

lbNo = new JLabel ("Account No:");


lbNo.setForeground (Color.black);
lbNo.setBounds (15, 20, 80, 25);
lbName = new JLabel ("Person Name:");
lbName.setForeground (Color.black);
lbName.setBounds (15, 55, 80, 25);
lbDate = new JLabel ("Last Transaction:");
lbDate.setForeground (Color.black);
lbDate.setBounds (15, 90, 100, 25);
lbBal = new JLabel ("Balance:");
lbBal.setForeground (Color.black);
lbBal.setBounds (15, 125, 80, 25);

txtNo = new JTextField ();


txtNo.setHorizontalAlignment (JTextField.RIGHT);

Bank Management System by RAVISHER SINGH BRAR (B.Tech (CSE), Roll Number 220280091)
txtNo.setBounds (125, 20, 200, 25);
txtName = new JTextField ();
txtName.setEnabled (false);
txtName.setBounds (125, 55, 200, 25);
txtDate = new JTextField ();
txtDate.setEnabled (false);
txtDate.setBounds (125, 90, 200, 25);
txtBal = new JTextField ();
txtBal.setHorizontalAlignment (JTextField.RIGHT);
txtBal.setEnabled (false);
txtBal.setBounds (125, 125, 200, 25);

//Restricting The User Input to only Numerics.


txtNo.addKeyListener (new KeyAdapter() {
public void keyTyped (KeyEvent ke) {
char c = ke.getKeyChar ();
if (!((Character.isDigit (c) || (c ==
KeyEvent.VK_BACK_SPACE)))) {
getToolkit().beep ();
ke.consume ();
}
}
}
);

//Aligning The Buttons.


btnFind = new JButton ("Search");
btnFind.setBounds (20, 165, 120, 25);
btnFind.addActionListener (this);
btnCancel = new JButton ("Cancel");
btnCancel.setBounds (200, 165, 120, 25);
btnCancel.addActionListener (this);

//Adding the All the Controls to Panel.


jpFind.add (lbNo);
jpFind.add (txtNo);
jpFind.add (lbName);
jpFind.add (txtName);
jpFind.add (lbDate);
jpFind.add (txtDate);
jpFind.add (lbBal);
jpFind.add (txtBal);
jpFind.add (btnFind);
jpFind.add (btnCancel);

//Adding Panel to Window.

Bank Management System by RAVISHER SINGH BRAR (B.Tech (CSE), Roll Number 220280091)
getContentPane().add (jpFind);

populateArray (); //Load All Existing Records in Memory.

//In the End Showing the New Account Window.


setVisible (true);

//Function use By Buttons of Window to Perform Action as User Click Them.


public void actionPerformed (ActionEvent ae) {

Object obj = ae.getSource();

if (obj == btnFind) {
if (txtNo.getText().equals("")) {
JOptionPane.showMessageDialog (this, "Please! Provide Id of
Customer to Search.",
"BankSystem - EmptyField",
JOptionPane.PLAIN_MESSAGE);
txtNo.requestFocus();
}
else {
rows = 0;
populateArray (); //Load All Existing Records in Memory.
findRec (); //Finding if Account No. Exist or Not.
}
}
if (obj == btnCancel) {
txtClear ();
setVisible (false);
dispose();
}

//Function use to load all Records from File when Application Execute.
void populateArray () {

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 ();

Bank Management System by RAVISHER SINGH BRAR (B.Tech (CSE), Roll Number 220280091)
}
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);
btnEnable ();
}
else {
try {
dis.close();
fis.close();
}
catch (Exception exp) { }
}
}

//Function use to Find Record by Matching the Contents of Records Array with ID
TextBox.
void findRec () {

boolean found = false;


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

Bank Management System by RAVISHER SINGH BRAR (B.Tech (CSE), Roll Number 220280091)
//Function which display Record from Array onto the Form.
public void showRec (int intRec) {

txtNo.setText (records[intRec][0]);
txtName.setText (records[intRec][1]);
txtDate.setText (records[intRec][2] + ", " + records[intRec][3] + ", " +
records[intRec][4]);
txtBal.setText (records[intRec][5]);

//Function use to Clear all TextFields of Window.


void txtClear () {

txtNo.setText ("");
txtName.setText ("");
txtDate.setText ("");
txtBal.setText ("");
txtNo.requestFocus ();

//Function use to Lock Controls of Window.


void btnEnable () {

txtNo.setEnabled (false);
btnFind.setEnabled (false);

Bank Management System by RAVISHER SINGH BRAR (B.Tech (CSE), Roll Number 220280091)
ViewCustomer.java
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.io.*;
import javax.swing.table.DefaultTableModel;

public class ViewCustomer extends JInternalFrame {

private JPanel jpShow = new JPanel ();

private DefaultTableModel dtmCustomer;


private JTable tbCustomer;
private JScrollPane jspTable;

private int row = 0;


private int total = 0;

//String Type Array use to Load Records into File.


private String rowData[][];

private FileInputStream fis;


private DataInputStream dis;

ViewCustomer () {

//super(Title, Resizable, Closable, Maximizable, Iconifiable)


super ("View All Account Holders", false, true, false, true);
setSize (475, 280);

jpShow.setLayout (null);

populateArray ();

tbCustomer = makeTable ();


jspTable = new JScrollPane (tbCustomer);
jspTable.setBounds (20, 20, 425, 200);

//Adding the Table to Panel.


jpShow.add (jspTable);

//Adding Panel to Window.


getContentPane().add (jpShow);

//In the End Showing the New Account Window.


setVisible (true);

Bank Management System by RAVISHER SINGH BRAR (B.Tech (CSE), Roll Number 220280091)
}

//Function use to load all Records from File when Window Open.
void populateArray () {

//String Type Array use to Load Records into File.


String rows[][] = new String [500][6];
try {
fis = new FileInputStream ("Bank.dat");
dis = new DataInputStream (fis);
//Loop to Populate the Array.
while (true) {
for (int i = 0; i < 6; i++) {
rows[row][i] = dis.readUTF ();
}
row++;
}
}
catch (Exception ex) {
total = row;
rowData = new String [total][4];
if (total == 0) {
JOptionPane.showMessageDialog (null, "Records File is
Empty.\nEnter Records to Display.",
"BankSystem - EmptyFile",
JOptionPane.PLAIN_MESSAGE);
}
else {
for (int i = 0; i < total; i++) {
rowData[i][0] = rows[i][0];
rowData[i][1] = rows[i][1];
rowData[i][2] = rows[i][2] + ", " + rows[i][3] + ", " +
rows[i][4];
rowData[i][3] = rows[i][5];
}
try {
dis.close();
fis.close();
}
catch (Exception exp) { }
}
}

Bank Management System by RAVISHER SINGH BRAR (B.Tech (CSE), Roll Number 220280091)
//Function to Create the Table and Add Data to Show.
private JTable makeTable () {

//String Type Array use to Give Table Column Names.


String cols[] = {"Account No.", "Customer Name", "Opening Date", "Bank
Balance"};

dtmCustomer = new DefaultTableModel (rowData, cols);


tbCustomer = new JTable (dtmCustomer) {
public boolean isCellEditable (int iRow, int iCol) {
return false; //Disable All Columns of Table.
}
};
//Sizing the Columns of Table.
(tbCustomer.getColumnModel().getColumn(0)).setPreferredWidth (180);
(tbCustomer.getColumnModel().getColumn(1)).setPreferredWidth (275);
(tbCustomer.getColumnModel().getColumn(2)).setPreferredWidth (275);
(tbCustomer.getColumnModel().getColumn(3)).setPreferredWidth (200);
tbCustomer.setRowHeight (20);
tbCustomer.setSelectionMode (ListSelectionModel.SINGLE_SELECTION);
return tbCustomer;

Bank Management System by RAVISHER SINGH BRAR (B.Tech (CSE), Roll Number 220280091)
ViewOne.java
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;

public class ViewOne extends JInternalFrame implements ActionListener {

private JPanel jpRec = new JPanel();


private JLabel lbNo, lbName, lbDate, lbBal;
private JTextField txtNo, txtName, txtDate, txtBal, txtRec;
private JButton btnFirst, btnBack, btnNext, btnLast;

private int recCount = 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];

private FileInputStream fis;


private DataInputStream dis;

ViewOne () {

// super(Title, Resizable, Closable, Maximizable, Iconifiable)


super ("View Account Holders", false, true, false, true);
setSize (350, 235);

jpRec.setLayout (null);

lbNo = new JLabel ("Account No:");


lbNo.setForeground (Color.black);
lbNo.setBounds (15, 20, 80, 25);
lbName = new JLabel ("Person Name:");
lbName.setForeground (Color.black);
lbName.setBounds (15, 55, 80, 25);
lbDate = new JLabel ("Last Transaction:");
lbDate.setForeground (Color.black);
lbDate.setBounds (15, 90, 100, 25);
lbBal = new JLabel ("Balance:");
lbBal.setForeground (Color.black);
lbBal.setBounds (15, 125, 80, 25);

txtNo = new JTextField ();


txtNo.setHorizontalAlignment (JTextField.RIGHT);

Bank Management System by RAVISHER SINGH BRAR (B.Tech (CSE), Roll Number 220280091)
txtNo.setEnabled (false);
txtNo.setBounds (125, 20, 200, 25);
txtName = new JTextField ();
txtName.setEnabled (false);
txtName.setBounds (125, 55, 200, 25);
txtDate = new JTextField ();
txtDate.setEnabled (false);
txtDate.setBounds (125, 90, 200, 25);
txtBal = new JTextField ();
txtBal.setHorizontalAlignment (JTextField.RIGHT);
txtBal.setEnabled (false);
txtBal.setBounds (125, 125, 200, 25);

//Aligninig The Navigation Buttons.


btnFirst = new JButton ("<<");
btnFirst.setBounds (15, 165, 50, 25);
btnFirst.addActionListener (this);
btnBack = new JButton ("<");
btnBack.setBounds (65, 165, 50, 25);
btnBack.addActionListener (this);
btnNext = new JButton (">");
btnNext.setBounds (225, 165, 50, 25);
btnNext.addActionListener (this);
btnLast = new JButton (">>");
btnLast.setBounds (275, 165, 50, 25);
btnLast.addActionListener (this);
txtRec = new JTextField ();
txtRec.setEnabled (false);
txtRec.setHorizontalAlignment (JTextField.CENTER);
txtRec.setBounds (115, 165, 109, 25);

//Adding the All the Controls to Panel.


jpRec.add (lbNo);
jpRec.add (txtNo);
jpRec.add (lbName);
jpRec.add (txtName);
jpRec.add (lbDate);
jpRec.add (txtDate);
jpRec.add (lbBal);
jpRec.add (txtBal);
jpRec.add (btnFirst);
jpRec.add (btnBack);
jpRec.add (btnNext);
jpRec.add (btnLast);
jpRec.add (txtRec);

Bank Management System by RAVISHER SINGH BRAR (B.Tech (CSE), Roll Number 220280091)
//Adding Panel to Window.
getContentPane().add (jpRec);

//Load All Existing Records in Memory and Display them on Form.


populateArray ();
showRec (0);

//In the End Showing the New Account Window.


setVisible (true);

//Function use By Buttons of Window to Perform Action as User Click Them.


public void actionPerformed (ActionEvent ae) {

Object obj = ae.getSource();

if (obj == btnFirst) {
recCount = 0;
showRec (recCount);
}
else if (obj == btnBack) {
recCount = recCount - 1;
if (recCount < 0) {
recCount = 0;
showRec (recCount);
JOptionPane.showMessageDialog (this, "You are on First
Record.",
"BankSystem - 1st Record",
JOptionPane.PLAIN_MESSAGE);
}
else {
showRec (recCount);
}
}
else if (obj == btnNext) {
recCount = recCount + 1;
if (recCount == total) {
recCount = total - 1;
showRec (recCount);
JOptionPane.showMessageDialog (this, "You are on Last
Record.",
"BankSystem - End of Records",
JOptionPane.PLAIN_MESSAGE);
}
else {

Bank Management System by RAVISHER SINGH BRAR (B.Tech (CSE), Roll Number 220280091)
showRec (recCount);
}
}
else if (obj == btnLast) {
recCount = total - 1;
showRec (recCount);
}

//Function use to load all Records from File when Application Execute.
void populateArray () {

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);
btnEnable ();
}
else {
try {
dis.close();
fis.close();
}
catch (Exception exp) { }
}
}

//Function which display Record from Array onto the Form.


public void showRec (int intRec) {

Bank Management System by RAVISHER SINGH BRAR (B.Tech (CSE), Roll Number 220280091)
txtNo.setText (records[intRec][0]);
txtName.setText (records[intRec][1]);
txtDate.setText (records[intRec][2] + ", " + records[intRec][3] + ", " +
records[intRec][4]);
txtBal.setText (records[intRec][5]);
if (total == 0) {
txtRec.setText (intRec + "/" + total); //Showing Record No. and Total
Records.
txtDate.setText ("");
}
else {
txtRec.setText ((intRec + 1) + "/" + total); //Showing Record No. and
Total Records.
}

//Function use to Lock all Buttons of Window.


void btnEnable () {

btnFirst.setEnabled (false);
btnBack.setEnabled (false);
btnNext.setEnabled (false);
btnLast.setEnabled (false);

Bank Management System by RAVISHER SINGH BRAR (B.Tech (CSE), Roll Number 220280091)
FindName.java
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;

public class FindName extends JInternalFrame implements ActionListener {

private JPanel jpFind = new JPanel();


private JLabel lbNo, lbName, lbDate, lbBal;
private JTextField txtNo, txtName, txtDate, txtBal;
private JButton btnFind, btnCancel;

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];

private FileInputStream fis;


private DataInputStream dis;

FindName () {

//super(Title, Resizable, Closable, Maximizable, Iconifiable)


super ("Search Customer [By Name]", false, true, false, true);
setSize (350, 235);

jpFind.setLayout (null);

lbNo = new JLabel ("Account No:");


lbNo.setForeground (Color.black);
lbNo.setBounds (15, 20, 80, 25);
lbName = new JLabel ("Person Name:");
lbName.setForeground (Color.black);
lbName.setBounds (15, 55, 80, 25);
lbDate = new JLabel ("Last Transaction:");
lbDate.setForeground (Color.black);
lbDate.setBounds (15, 90, 100, 25);
lbBal = new JLabel ("Balance:");
lbBal.setForeground (Color.black);
lbBal.setBounds (15, 125, 80, 25);

txtNo = new JTextField ();


txtNo.setHorizontalAlignment (JTextField.RIGHT);

Bank Management System by RAVISHER SINGH BRAR (B.Tech (CSE), Roll Number 220280091)
txtNo.setEnabled (false);
txtNo.setBounds (125, 20, 200, 25);
txtName = new JTextField ();
txtName.setBounds (125, 55, 200, 25);
txtDate = new JTextField ();
txtDate.setEnabled (false);
txtDate.setBounds (125, 90, 200, 25);
txtBal = new JTextField ();
txtBal.setHorizontalAlignment (JTextField.RIGHT);
txtBal.setEnabled (false);
txtBal.setBounds (125, 125, 200, 25);

//Aligning The Buttons.


btnFind = new JButton ("Search");
btnFind.setBounds (20, 165, 120, 25);
btnFind.addActionListener (this);
btnCancel = new JButton ("Cancel");
btnCancel.setBounds (200, 165, 120, 25);
btnCancel.addActionListener (this);

//Adding the All the Controls to Panel.


jpFind.add (lbNo);
jpFind.add (txtNo);
jpFind.add (lbName);
jpFind.add (txtName);
jpFind.add (lbDate);
jpFind.add (txtDate);
jpFind.add (lbBal);
jpFind.add (txtBal);
jpFind.add (btnFind);
jpFind.add (btnCancel);

//Adding Panel to Window.


getContentPane().add (jpFind);

populateArray (); //Load All Existing Records in Memory.

//In the End Showing the New Account Window.


setVisible (true);

//Function use By Buttons of Window to Perform Action as User Click Them.


public void actionPerformed (ActionEvent ae) {

Object obj = ae.getSource();

Bank Management System by RAVISHER SINGH BRAR (B.Tech (CSE), Roll Number 220280091)
if (obj == btnFind) {
if (txtName.getText().equals ("")) {
JOptionPane.showMessageDialog (this, "Please! Provide Name of
Customer to Search.",
"BankSystem - EmptyField",
JOptionPane.PLAIN_MESSAGE);
txtName.requestFocus();
}
else {
rows = 0;
populateArray (); //Load All Existing Records in Memory.
findRec (); //Finding if Account No. Exist or Not.
}
}
if (obj == btnCancel) {
txtClear ();
setVisible (false);
dispose();
}

//Function use to load all Records from File when Application Execute.
void populateArray () {

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);
btnEnable ();
}

Bank Management System by RAVISHER SINGH BRAR (B.Tech (CSE), Roll Number 220280091)
else {
try {
dis.close();
fis.close();
}
catch (Exception exp) { }
}
}

//Function use to Find Record by Matching the Contents of Records Array with ID
TextBox.
void findRec () {

boolean found = false;


for (int x = 0; x < total; x++) {
if (records[x][1].equalsIgnoreCase (txtName.getText())) {
found = true;
showRec (x);
break;
}
}
if (found == false) {
JOptionPane.showMessageDialog (this, "Customer " + txtName.getText ()
+ " doesn't Exist.",
"BankSystem - WrongNo",
JOptionPane.PLAIN_MESSAGE);
txtClear ();
}

//Function which display Record from Array onto the Form.


public void showRec (int intRec) {

txtNo.setText (records[intRec][0]);
txtName.setText (records[intRec][1]);
txtDate.setText (records[intRec][2] + ", " + records[intRec][3] + ", " +
records[intRec][4]);
txtBal.setText (records[intRec][5]);

//Function use to Clear all TextFields of Window.


void txtClear () {

Bank Management System by RAVISHER SINGH BRAR (B.Tech (CSE), Roll Number 220280091)
txtNo.setText ("");
txtName.setText ("");
txtDate.setText ("");
txtBal.setText ("");
txtName.requestFocus ();

//Function use to Lock Controls of Window.


void btnEnable () {

txtName.setEnabled (false);
btnFind.setEnabled (false);

Bank Management System by RAVISHER SINGH BRAR (B.Tech (CSE), Roll Number 220280091)
DeleteCustomer.java
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;

public class DeleteCustomer extends JInternalFrame implements ActionListener {

private JPanel jpDel = new JPanel();


private JLabel lbNo, lbName, lbDate, lbBal;
private JTextField txtNo, txtName, txtDate, txtBal;
private JButton btnDel, btnCancel;

private int recCount = 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];

private FileInputStream fis;


private DataInputStream dis;

DeleteCustomer () {

// super(Title, Resizable, Closable, Maximizable, Iconifiable)


super ("Delete Account Holder", false, true, false, true);
setSize (350, 235);

jpDel.setLayout (null);

lbNo = new JLabel ("Account No:");


lbNo.setForeground (Color.black);
lbNo.setBounds (15, 20, 80, 25);
lbName = new JLabel ("Person Name:");
lbName.setForeground (Color.black);
lbName.setBounds (15, 55, 90, 25);
lbDate = new JLabel ("Last Transaction:");
lbDate.setForeground (Color.black);
lbDate.setBounds (15, 90, 100, 25);
lbBal = new JLabel ("Balance:");
lbBal.setForeground (Color.black);
lbBal.setBounds (15, 125, 80, 25);

txtNo = new JTextField ();


txtNo.setHorizontalAlignment (JTextField.RIGHT);

Bank Management System by RAVISHER SINGH BRAR (B.Tech (CSE), Roll Number 220280091)
txtNo.setBounds (125, 20, 200, 25);
txtName = new JTextField ();
txtName.setEnabled (false);
txtName.setBounds (125, 55, 200, 25);
txtDate = new JTextField ();
txtDate.setEnabled (false);
txtDate.setBounds (125, 90, 200, 25);
txtBal = new JTextField ();
txtBal.setEnabled (false);
txtBal.setHorizontalAlignment (JTextField.RIGHT);
txtBal.setBounds (125, 125, 200, 25);

//Aligning The Buttons.


btnDel = new JButton ("Delete");
btnDel.setBounds (20, 165, 120, 25);
btnDel.addActionListener (this);
btnCancel = new JButton ("Cancel");
btnCancel.setBounds (200, 165, 120, 25);
btnCancel.addActionListener (this);

//Adding the All the Controls to Panel.


jpDel.add (lbNo);
jpDel.add (txtNo);
jpDel.add (lbName);
jpDel.add (txtName);
jpDel.add (lbDate);
jpDel.add (txtDate);
jpDel.add (lbBal);
jpDel.add (txtBal);
jpDel.add (btnDel);
jpDel.add (btnCancel);

//Restricting The User Input to only Numerics in Numeric TextBoxes.


txtNo.addKeyListener (new KeyAdapter() {
public void keyTyped (KeyEvent ke) {
char c = ke.getKeyChar ();
if (!((Character.isDigit (c) || (c ==
KeyEvent.VK_BACK_SPACE)))) {
getToolkit().beep ();
ke.consume ();
}
}
}
);
//Checking the Accunt No. Provided By User on Lost Focus of the TextBox.
txtNo.addFocusListener (new FocusListener () {

Bank Management System by RAVISHER SINGH BRAR (B.Tech (CSE), Roll Number 220280091)
public void focusGained (FocusEvent e) { }
public void focusLost (FocusEvent fe) {
if (txtNo.getText().equals ("")) { }
else {
rows = 0;
populateArray (); //Load All Existing Records in
Memory.
findRec (); //Finding if Account No. Already
Exist or Not.
}
}
}
);

//Adding Panel to Window.


getContentPane().add (jpDel);

populateArray (); //Load All Existing Records in Memory.

//In the End Showing the New Account Window.


setVisible (true);

//Function use By Buttons of Window to Perform Action as User Click Them.


public void actionPerformed (ActionEvent ae) {

Object obj = ae.getSource();

if (obj == btnDel) {
if (txtNo.getText().equals("")) {
JOptionPane.showMessageDialog (this, "Please! Provide Id of
Customer.",
"BankSystem - EmptyField",
JOptionPane.PLAIN_MESSAGE);
txtNo.requestFocus();
}
else {
deletion (); //Confirm Deletion of Current Record.
}
}
if (obj == btnCancel) {
txtClear ();
setVisible (false);
dispose();
}

Bank Management System by RAVISHER SINGH BRAR (B.Tech (CSE), Roll Number 220280091)
}

//Function use to load all Records from File when Application Execute.
void populateArray () {

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);
btnEnable ();
}
else {
try {
dis.close();
fis.close();
}
catch (Exception exp) { }
}
}

//Function use to Find Record by Matching the Contents of Records Array with ID
TextBox.
void findRec () {

boolean found = false;


for (int x = 0; x < total; x++) {
if (records[x][0].equals (txtNo.getText())) {
found = true;
showRec (x);

Bank Management System by RAVISHER SINGH BRAR (B.Tech (CSE), Roll Number 220280091)
break;
}
}
if (found == false) {
String str = txtNo.getText ();
txtClear ();
JOptionPane.showMessageDialog (this, "Account No. " + str + " doesn't
Exist.",
"BankSystem - WrongNo",
JOptionPane.PLAIN_MESSAGE);
}

//Function which display Record from Array onto the Form.


void showRec (int intRec) {

txtNo.setText (records[intRec][0]);
txtName.setText (records[intRec][1]);
txtDate.setText (records[intRec][2] + ", " + records[intRec][3] + ", " +
records[intRec][4]);
txtBal.setText (records[intRec][5]);
recCount = intRec;

//Confirming the Deletion Decision made By User of Program.


void deletion () {

try {
//Show a Confirmation Dialog.
int reply = JOptionPane.showConfirmDialog (this,
"Are you Sure you want to Delete\n" + txtName.getText ()
+ " Record From BankSystem?",
"Bank System - Delete", JOptionPane.YES_NO_OPTION,
JOptionPane.PLAIN_MESSAGE);
//Check the User Selection.
if (reply == JOptionPane.YES_OPTION) {
delRec (); //Delete the Selected Contents of Array.
}
else if (reply == JOptionPane.NO_OPTION) { }
}

catch (Exception e) {}

Bank Management System by RAVISHER SINGH BRAR (B.Tech (CSE), Roll Number 220280091)
//Function use to Delete an Element from the Array.
void delRec () {

try {
if (records != null) {
for(int i = recCount; i < total; i++) {
for (int r = 0; r < 6; r++) {
records[i][r] = records[i+1][r];

if (records[i][r] == null) break;


}
}
total = total - 1;
deleteFile ();
}
}
catch (ArrayIndexOutOfBoundsException ex) { }

//Function use to Save Records to File After Deleting the Record of User Choice.
void deleteFile () {

try {
FileOutputStream fos = new FileOutputStream ("Bank.dat");
DataOutputStream dos = new DataOutputStream (fos);
if (records != null) {
for (int i = 0; i < total; i++) {
for (int r = 0; r < 6; r++) {
dos.writeUTF (records[i][r]);
if (records[i][r] == null) break;
}
}
JOptionPane.showMessageDialog (this, "Record has been Deleted
Successfuly.",
"BankSystem - Record Deleted",
JOptionPane.PLAIN_MESSAGE);
txtClear ();
}
else { }
dos.close();
fos.close();
}
catch (IOException ioe) {

Bank Management System by RAVISHER SINGH BRAR (B.Tech (CSE), Roll Number 220280091)
JOptionPane.showMessageDialog (this, "There are Some Problem with
File",
"BankSystem - Problem",
JOptionPane.PLAIN_MESSAGE);
}

//Function use to Clear all TextFields of Window.


void txtClear () {

txtNo.setText ("");
txtName.setText ("");
txtDate.setText ("");
txtBal.setText ("");
txtNo.requestFocus ();

//Function use to Lock Controls of Window.


void btnEnable () {

txtNo.setEnabled (false);
btnDel.setEnabled (false);

Bank Management System by RAVISHER SINGH BRAR (B.Tech (CSE), Roll Number 220280091)
CONCLUSION

The project Bank System is for computerizing the working in a Banking System. The software
takes care of all the requirements of Banking and is capable to provide easy and effective storage
of information related to customer that come up to the Bank.

It generates daily dealing with customers; i.e. Open New accounts, Deposit money,
Withdrawal money, Search customer and much more.

Bank Management System by RAVISHER SINGH BRAR (B.Tech (CSE), Roll Number 220280091)
REFERENCES
Books:-

➢ JAVA: The Complete reference-Herbert Schildt.

➢ Java 6 Programming Black Book-New Ed-Kogent.

➢ Programming in Java- E.Balaguruswamy.

Websites:-

➢ www.schools3.com

➢ www.oracle.com

Bank Management System by RAVISHER SINGH BRAR (B.Tech (CSE), Roll Number 220280091)

You might also like