trainingjava
trainingjava
UNIT STRUCTURE
1.1Java
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).
Bank Management System by RAVISHER SINGH BRAR (B.Tech (CSE), Roll Number 220280091)
1.2.1 Object
1.2.2 Class
1.2.5 Inheritance
1.2.6Polymorphism
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.
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.
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.
Bank Management System by RAVISHER SINGH BRAR (B.Tech (CSE), Roll Number 220280091)
1991 Announcement of a new language named ―Oak‖
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.
1.4.5 Distributed
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.
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.
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.
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.
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
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.
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.
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.
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
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.4 Javap (Java diassembler, which convert byte code into program description)
For compiling and running the program we have to use following commands:
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
javac abc.java
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
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:
Javax.swing.plaf. Basic: Contains classes that define the default look and feel of swing
components.
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.
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.
• It does not restrict the type of queries passed to an underlying DBMS driver
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
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.
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.
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.
After thoroughly analyzing the existing system, some objectives of the proposed system
have been set:
• Adequate security.
Bank Management System by RAVISHER SINGH BRAR (B.Tech (CSE), Roll Number 220280091)
• Application must be user friendly.
• Saving of time.
• Fast operations.
Bank Management System by RAVISHER SINGH BRAR (B.Tech (CSE), Roll Number 220280091)
SYSTEM REQUIREMENTS
• Windows XP or Higher
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.*;
setVisible (true);
JEditorPane html;
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);
}
if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
linkActivated(e.getURL());
}
}
Cursor c = html.getCursor();
Cursor waitCursor = Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR);
html.setCursor(waitCursor);
SwingUtilities.invokeLater(new PageLoader(u, c));
PageLoader(URL u, Cursor c) {
url = u;
cursor = c;
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.*;
NewAccount () {
Bank Management System by RAVISHER SINGH BRAR (B.Tech (CSE), Roll Number 220280091)
lbDeposit.setForeground (Color.black);
lbDeposit.setBounds (15, 125, 80, 25);
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);
}
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 () {
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++;
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);
}
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.*;
DepositMoney () {
jpDep.setLayout (null);
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);
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.
}
}
}
);
Bank Management System by RAVISHER SINGH BRAR (B.Tech (CSE), Roll Number 220280091)
//Adding Panel to Window.
getContentPane().add (jpDep);
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 () {
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);
}
txtNo.setText (records[intRec][0]);
txtName.setText (records[intRec][1]);
curr = Integer.parseInt (records[intRec][5]);
recCount = intRec;
txtNo.setText ("");
txtName.setText ("");
txtDeposit.setText ("");
txtNo.requestFocus ();
//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);
}
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.*;
WithdrawMoney () {
jpWith.setLayout (null);
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);
Bank Management System by RAVISHER SINGH BRAR (B.Tech (CSE), Roll Number 220280091)
}
}
}
);
Bank Management System by RAVISHER SINGH BRAR (B.Tech (CSE), Roll Number 220280091)
//Adding Panel to Window.
getContentPane().add (jpWith);
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 () {
txtNo.setText (records[intRec][0]);
txtName.setText (records[intRec][1]);
curr = Integer.parseInt (records[intRec][5]);
recCount = intRec;
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 () {
//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);
}
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.*;
FindAccount () {
jpFind.setLayout (null);
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);
Bank Management System by RAVISHER SINGH BRAR (B.Tech (CSE), Roll Number 220280091)
getContentPane().add (jpFind);
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 () {
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]);
txtNo.setText ("");
txtName.setText ("");
txtDate.setText ("");
txtBal.setText ("");
txtNo.requestFocus ();
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;
ViewCustomer () {
jpShow.setLayout (null);
populateArray ();
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 () {
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 () {
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.*;
ViewOne () {
jpRec.setLayout (null);
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);
Bank Management System by RAVISHER SINGH BRAR (B.Tech (CSE), Roll Number 220280091)
//Adding Panel to Window.
getContentPane().add (jpRec);
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) { }
}
}
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.
}
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.*;
FindName () {
jpFind.setLayout (null);
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);
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 () {
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]);
Bank Management System by RAVISHER SINGH BRAR (B.Tech (CSE), Roll Number 220280091)
txtNo.setText ("");
txtName.setText ("");
txtDate.setText ("");
txtBal.setText ("");
txtName.requestFocus ();
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.*;
DeleteCustomer () {
jpDel.setLayout (null);
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);
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.
}
}
}
);
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 () {
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);
}
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;
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];
//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);
}
txtNo.setText ("");
txtName.setText ("");
txtDate.setText ("");
txtBal.setText ("");
txtNo.requestFocus ();
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:-
Websites:-
➢ www.schools3.com
➢ www.oracle.com
Bank Management System by RAVISHER SINGH BRAR (B.Tech (CSE), Roll Number 220280091)