Sie sind auf Seite 1von 105

LIBRARY MANAGEMENT SYSTEM

Table of contents

Page No.

1 Introduction
1.1 Problem Definition 1.2 Objective & Scope 1.3 Proposed System 1.4 Assumptions & Constraints 1.5 System Requirements 3 3 5 6 7

Software Requirement Specification[SRS] & Design 2.1 Introduction Purpose System overview 2.2 Overall description Product perspective Product functions User characteristics Constraints, assumptions and dependencies 10 10 10 11 8 8

Specific requirements 3.1 Interface requirements 3.2 Functional requirements 3.3 Performance requirements 3.4 Design constraints 3.5 Database Schema 3.6 Software System attributes 3.7 Detailed Life Cycle of the project 12 12 13 13 14 16 16

Sumeet Dhende (2012450009) Jeet Dholakia (2012450010)

Page 1

LIBRARY MANAGEMENT SYSTEM

Project Implementation 4.1 Work Break down Structure 4.2 Gantt Chart 4.3 Pert Chart 4.4 Code with reference to design 4.5 Snapshot of UI & Reports 19 20 22 23 96

Future Enhancements

102

Limitations

103

Conclusion

104

Bibliographies

105

Sumeet Dhende (2012450009) Jeet Dholakia (2012450010)

Page 2

LIBRARY MANAGEMENT SYSTEM

CHAPTER 1 INTRODUCTION
1.1 Problem Definition
TO DEVELOP A LIBRARY MANAGEMENT SYSTEM. Library Management System can be used by education institutes to maintain the records of books easily. Achieving this objective is difficult using manual system as the information is scattered, can be redundant and collecting relevant information may be very time consuming. All these problems are solved using this project. As there are many books present in library and also there are various books issued by librarians to the members. It is very difficult to maintain huge catalogue within reasonable space constraints manually and to maintain the same is very time and space consuming process. If we want complete information of available books or issued books at any given point of time it is difficult to get it. Although manual system can handle but there are some flaws in this system: Data Redundancy. Lot Of Paperwork Involved. Time Consuming Process.

Risk of Data Loss etc 1.2 Objective & Scope


Objective The system is a standalone system. The admin can issue and renew the book. The system empowers the administrator to issue fines on books that are overdue. The system can maintain the data about the books. The system can categorize the books according to the courses.

Sumeet Dhende (2012450009) Jeet Dholakia (2012450010)

Page 3

LIBRARY MANAGEMENT SYSTEM

Scope Without a Library management System, managing and maintaining the details of the book is a tedious job for any college. Library management system will store all the details of the books including their category, availability and also maintains the details about the students to whom the books are issued. Login module: Login module will help in authentication of user accounts. Users who have valid login id and password can only login into their respective accounts Search module: Suppose there are hundreds of students and from this we have to search a particular student and we know the name of the student .In manual system it is a tedious task though we know the name of the student, but using this module we can easily search the student by specifying the name of the student in the search criteria. Thus this module will help the administrator in searching the student with various criteria easily. Addition of Books: This module helps to add the books details according to category wise. Deletion of Books: This module provides the admin option to delete the existing books from the given category and the admin can delete the already existing books from the database. Addition of Student Details: This module helps to add and maintained the details about the students to whom the books have been issued, the details of the students are categories according to their courses. Fine Module: If the student doesnt returns the books on the given due date than this module helps to imply fine on that particular student Admin id Admin password Book Details Book Issued Date Book Return Date Student id

Sumeet Dhende (2012450009) Jeet Dholakia (2012450010)

Page 4

LIBRARY MANAGEMENT SYSTEM

Existing System According to existing manual system it very tedious and time consuming work to maintain consistency of books record. There are large numbers of students who regularly take and returns books and to maintain this large data manually. It takes lot of paper work and consumes more time and place. There is also a risk of data loss because of degradation of registers, papers misplace from register etc. Apart from this there is risk of duplication of data and manipulation of data without prior authority and maintaining that record and keep them safe for long period of time is very difficult. On other hand data of particular books and students whose data is scattered in different registers and very hard for anyone to gather data of particular student or books.

1.3 Proposed System


Library Management System can be used by education institutes to maintain the records of books according to their categories and to whom they are issued easily. Achieving this objective is difficult using a manual system as the information is scattered, can be redundant and collecting relevant information may be very time consuming. All these problems are solved using this project.

Sumeet Dhende (2012450009) Jeet Dholakia (2012450010)

Page 5

LIBRARY MANAGEMENT SYSTEM

1.4 Assumptions & Constraints

Assumptions:

All the data entered will be correct and up to date.

Administrator is created in the system already.

This software package is developed using JAVA as front end, MS SQL as the back end which is supported by Microsoft Windows XP.

The code should be free with compilation errors or system errors. The product must have an interface which is simple enough to understand.

Constraints:

Any update regarding the availability of books, return of books, fine imposed on the students, issued date and due date are to be recorded to have updated and correct values.

Login and password is used for identification of admin.

Sumeet Dhende (2012450009) Jeet Dholakia (2012450010)

Page 6

LIBRARY MANAGEMENT SYSTEM

1.5 System Requirements


Operating Systems: Microsoft Windows or Linux

Technologies Used:

Front End: JAVA RDBMS(Back end): MySQL

Software Requirements: Netbeans IDE 7.0 Microsoft Windows or Linux. XAMPP Server with MySQL.

Hardware Requirements: Intel Pentium IV processor or equivalent or higher 512 MB Ram or Higher 20 GB HDD or Higher Network Connectivity

Sumeet Dhende (2012450009) Jeet Dholakia (2012450010)

Page 7

LIBRARY MANAGEMENT SYSTEM

CHAPTER 2 SOFTWARE REQUIREMENT SPECIFICATIONS


2.1 Introduction:
Purpose: An SRS establishes the basis for the agreement between the client and the developer on what the software product will do. SRS provides a reference for validation of the final product. A high quality SRS is a prerequisite to high-quality software. A high quality SRS reduces the development cost. System Overview: The basic issues an SRS must address are: Functional Requirements Performance Requirements Design constraints imposed on implementation External interface Requirements

Sumeet Dhende (2012450009) Jeet Dholakia (2012450010)

Page 8

LIBRARY MANAGEMENT SYSTEM


START

Login

Books

Members

Search

Loan

Reserve

Add Books

Add Members

Borrow a Book

Reserve a Book

List All Books

List All Members

Return A Book

List Available Books

Edit Members

Issued Book Details

List Borrowed Books

Remove Members

Edit Books

Member Info

Remove Books

STOP

Sumeet Dhende (2012450009) Jeet Dholakia (2012450010)

Page 9

LIBRARY MANAGEMENT SYSTEM

2.2 Overall Description


Product Perspective: The Student Information System is a replacement for traditional method of saving documents in paper format or in electronic format where conventional methods are used. The SIS is an advanced system to store, edit & manage in a secure manner Product Functions: Administrator: Login and logout to/from the account Add, view, modify, search and delete all the details of Books. Delete book from particular category. Add, view, edit, search and remove Category. Can view the due dates of the issued books. Can view the details related to books returned.

User Characteristics: Users of this system are librarian of the college who is administrator who maintains the system. The librarian should have basic knowledge of computers and internet browsing. The administrator should have some more knowledge, much about the system modules. So the admin can rectify problems caused due to catastrophic failures like hardware or power failures. Friendly graphical user interface and documents with the system will be sufficient to educate a user on how to use the system effectively, without any problems or difficulties. General users with basic computer skills can use this software. Knowledgeable User Novice User Expert User

Sumeet Dhende (2012450009) Jeet Dholakia (2012450010)

Page 10

LIBRARY MANAGEMENT SYSTEM

Constraints, Assumptions and Dependencies: The success of the system depends on: Hardware specifications of the server machine Ratio of number of user machines to server machines

Along with the system, the following third party programs will be required for the best experience: Netbeans IDE. MySQL.

Sumeet Dhende (2012450009) Jeet Dholakia (2012450010)

Page 11

LIBRARY MANAGEMENT SYSTEM

CHAPTER 3
SPECIFIC REQUIREMENTS AND PROJECT ANALYSIS AND DESIGN
3.1 Interface Requirements:
User Interface: A software provides the front-end, i.e. the user interface. Login Admin o Add Edit, Remove and Search Borrowers. o Add Edit, Remove and Search Borrowed books. o Add Edit, Remove and Search Books. o Search and Preview due dates of the Books. o Search and Preview Returned dates of the Books. o Add Edit, Remove and Search Categories. o Add and Remove Yearly Records. o Add Edit, Remove and Search Sections.

3.2 Functional Requirements:


Login: An administrator can login to the system and access the different types of functionalities. Search: Admin can search for the various types of functionality in the software like search of books, any particular books category wise, due date of the book, issue date of the book, borrowers. Sumeet Dhende (2012450009) Jeet Dholakia (2012450010) Page 12

LIBRARY MANAGEMENT SYSTEM

Addition of Records: Admin can add different types of books, borrowers, categories and different type of records. Deletion of Records: Admin has rights to delete different types of records like books, borrowers, categories and other records. Editing: Admin can edit the details related to books, category of books, borrowers, due date and returned date.

3.3 Performance requirements:


Time: The library management system is to be developed in 30 days. The deadline should not exceed beyond 15 days. The tasks should divided in such a way that the project can be completed in minimum possible time. Cost: To develop this project all open source software are used. Both JAVA and MySQL are open source and hence there is no cost of the software used. Hardware requirements are also basic and hence there is no need to extra investment on hardware. Quality: The quality of the software is to be maintained. although the time is less but the task should be manage in such way that maximum possible functionalities are implemented.

3.4 Design constraints:


The development of the system can be done using any basic text editor and using XAMP's developers interface. The system can be used on any operating system with a web browser. Sumeet Dhende (2012450009) Jeet Dholakia (2012450010) Page 13

LIBRARY MANAGEMENT SYSTEM

3.5 Database Schema:


Books Column BookID Subject Title Author Publisher Copyright Edition Pages ISBN NumberOfBooks NumberOfAvailabeBooks Type integer varchar(20) varchar(20) varchar(20) Varchar(20) integer integer integer Varchar(50) Integer Integer CONSTRAINT Primary Key Not Null Not Null Not Null Not Null Not Null Not Null Not Null Not Null Not Null Not Null Not Null Not Null Not Null Not Null

NumberOfBorrowedBooks integer Library Available ShelfNo Varchar(10) integer integer

Sumeet Dhende (2012450009) Jeet Dholakia (2012450010)

Page 14

LIBRARY MANAGEMENT SYSTEM

Borrow

Column BookID MemberID DayOfBorrowed DayOfReturn

Type integer varchar(20) varchar(20) varchar(20)

CONSTRAINT Foreign Key Foreign Key Not Null Not Null

Members

Column MemberID ID Password NAME EMAIL Major NumberOfBooks Mony Expired

Type integer integer varchar(20) varchar(20) varchar(20) varchar(20) integer integer datetime

CONSTRAINT Primary Key Not Null Not Null Not Null

Not Null Not Null Not Null Not Null

Sumeet Dhende (2012450009) Jeet Dholakia (2012450010)

Page 15

LIBRARY MANAGEMENT SYSTEM

3.6 Software System Attributes:


The system was developed considering the following attributes: Security Efficient resource utilization Ease in uploading and sharing documents Response time Efficient and consistent logic Maintainability

3.7 Detailed life Cycle of the Project:


The general methodology in developing a system is involved in different phases which describe the systems life cycle model for developing software project. The concept includes not only forward motion but also have the possibility to return that is cycle back to an activity previously completed. This cycle back or feedback may occur as a result of the failure with the system to meet a performance objective or as a result of changes in redefinition of System activities. The basic WATERFALL MODEL is being used that is it's stages.

These are as follows: Requirement Analysis Phase Design Phase Development Phase Coding Phase Testing Phase Implementation Phase Post Implementation Phase

Sumeet Dhende (2012450009) Jeet Dholakia (2012450010)

Page 16

LIBRARY MANAGEMENT SYSTEM

Phases of Waterfall Model:

REQUIREMENT ANALYSIS This phase includes the definition of the problem. In order to identify the problem: we have to know information about the problem the purpose of the evaluation for the problem to be known. To know the clients requirements and the objectives of the project, a questionnaire was prepared and the client was made to answer it. On the basis of the questionnaire, the problem is defined and evaluated. The SRS is made and requirement analysis is done.

DESIGN Software design is processes through which the requirements are translated into are presentation of software. The design of the system is in modular form i.e. the software is logically partitioned into components that perform specific functions and sub functions. The

Sumeet Dhende (2012450009) Jeet Dholakia (2012450010)

Page 17

LIBRARY MANAGEMENT SYSTEM

Design Phase leads to modules like process selection which exhibit independent functional characteristics .These modules arent interconnected. It even leads to interfaces that reduce t he complexity of the connections between modules and with that external environment.

DEVELOPMENT The development phase includes choosing of a suitable s/w to solve the particular problem given the various facilities and the sophistication in the selected software gives a better development of the problem. Here the software was built using. The data is stored in Database files for easier access.

CODING The coding phase is for retranslating the design of the system produced during the design phase into code in a given programming language which can be executed by a computer and which performs the computation specified by the design. We have used JAVA language and its basic concepts for coding the software system.

TESTING Testing is done in various ways such as testing the algorithm, programming code, sample data debugging is one. Testing has been done by checking each and every module and also to check the validations.

IMPLEMENTATION After testing is over project is implemented by providing training to the users and providing manuals so that they can be refreshed as and when needed.

POST IMPLEMENTATION If any problem occurs after the implemented they are removed from time to time so that so that the users can work on the prepared system easily finally a satisfied user when all things are almost right. Sumeet Dhende (2012450009) Jeet Dholakia (2012450010)

Page 18

LIBRARY MANAGEMENT SYSTEM

CHAPTER 4 PROJECT IMPLEMENTATION


4.1 Work Breakdown Structure
Library Management System

Books
Add List All Available Borrowed Edit Remove

Members
Add List All Edit Remove Info

Search

Loan
Borrow Return Details

Reserve

Help

About Us

Sumeet Dhende (2012450009) Jeet Dholakia (2012450010)

Page 19

LIBRARY MANAGEMENT SYSTEM


4.2 Gantt Chart

Sumeet Dhende (2012450009) Jeet Dholakia (2012450010)

Page 20

LIBRARY MANAGEMENT SYSTEM

Sumeet Dhende (2012450009) Jeet Dholakia (2012450010)

Page 21

LIBRARY MANAGEMENT SYSTEM


4.3 Pert Chart

Sumeet Dhende (2012450009) Jeet Dholakia (2012450010)

Page 22

LIBRARY MANAGEMENT SYSTEM


4.4 Code with reference to design
AddBooks.java //import the packages for using the classes in them into the program import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; public class AddBooks extends JInternalFrame { //for creating the North Panel private JPanel northPanel = new JPanel(); //for creaing the North Label private JLabel northLabel = new JLabel("BOOK INFORMATION"); //for creating the Center Panel private JPanel centerPanel = new JPanel(); //for creating an Internal Panel in the center panel private JPanel informationLabelPanel = new JPanel(); //for creating an array of JLabel private JLabel[] informationLabel = new JLabel[10]; private JLabel lblShelfNo = new JLabel(" Shelf No"); private JTextField txtShelfNo = new JTextField(); //for creating an array of String

Sumeet Dhende (2012450009) Jeet Dholakia (2012450010)

Page 23

LIBRARY MANAGEMENT SYSTEM


private String[] informationString = { " The book subject: ", " The book title: ", " The name of the Author(s): ", " The name of the Publisher: ", " Copyright for the book: ", " The edition number: ", " The number of Pages: ", " ISBN for the book: ", " The number of copies: ", " The name of the Library: " }; //for creating an Internal Panel in the center panel private JPanel informationTextFieldPanel = new JPanel(); //for creating an array of JTextField private JTextField[] informationTextField = new JTextField[10]; //for creating an Internal Panel in the center panel private JPanel insertInformationButtonPanel = new JPanel(); //for creating a button private JButton insertInformationButton = new JButton("Insert the Information"); //for creating South Panel private JPanel southPanel = new JPanel(); //for creating a button private JButton OKButton = new JButton("Exit"); //create objects from another classes for using them in the ActionListener private Books book; //for creating an array of string to store the data private String[] data; //for setting availble option to true private boolean availble = true; //for checking the information from the text field Sumeet Dhende (2012450009) Jeet Dholakia (2012450010) Page 24

LIBRARY MANAGEMENT SYSTEM


public boolean isCorrect() { data = new String[10]; for (int i = 0; i < informationLabel.length; i++) { if (!informationTextField[i].getText().equals("")) { data[i] = informationTextField[i].getText(); } else { return false; } } return true; } //for setting the array of JTextField to empty public void clearTextField() { for (int i = 0; i < informationTextField.length; i++) { informationTextField[i].setText(null); } txtShelfNo.setText(null); } //constructor of addBooks public AddBooks() { //for setting the title for the internal frame super("Add Books", false, true, false, true); //for setting the icon setFrameIcon(new ImageIcon(ClassLoader.getSystemResource("images/Add16.gif"))); //for getting the graphical user interface components display area Sumeet Dhende (2012450009) Jeet Dholakia (2012450010) Page 25

LIBRARY MANAGEMENT SYSTEM


Container cp = getContentPane(); //for setting the layout northPanel.setLayout(new FlowLayout(FlowLayout.CENTER)); //for setting the font for the North Panel northLabel.setFont(new Font("Tahoma", Font.BOLD, 14)); //for adding the label in the North Panel northPanel.add(northLabel); //for adding the north panel to the container cp.add("North", northPanel); //for setting the layout centerPanel.setLayout(new BorderLayout()); //for setting the border to the panel centerPanel.setBorder(BorderFactory.createTitledBorder("Add a new book:")); //for setting the layout informationLabelPanel.setLayout(new GridLayout(11, 1, 1, 1)); for (int i = 0; i < informationLabel.length; i++) { informationLabelPanel.add(informationLabel[i] = new JLabel(informationString[i])); informationLabel[i].setFont(new Font("Tahoma", Font.BOLD, 11)); } centerPanel.add("West", informationLabelPanel); //for setting the layout informationTextFieldPanel.setLayout(new GridLayout(11, 1, 1, 1));

for (int i = 0; i < informationTextField.length; i++) { informationTextFieldPanel.add(informationTextField[i] = new JTextField(25)); Sumeet Dhende (2012450009) Jeet Dholakia (2012450010) Page 26

LIBRARY MANAGEMENT SYSTEM


informationTextField[i].setFont(new Font("Tahoma", Font.PLAIN, 11)); } lblShelfNo.setFont(new Font("Tahoma", Font.BOLD, 11)); informationLabelPanel.add(lblShelfNo); txtShelfNo.setFont(new Font("Tahoma", Font.PLAIN, 11)); informationTextFieldPanel.add(txtShelfNo); centerPanel.add("East", informationTextFieldPanel); insertInformationButtonPanel.setLayout(new FlowLayout(FlowLayout.RIGHT)); insertInformationButton.setFont(new Font("Tahoma", Font.BOLD, 11)); insertInformationButtonPanel.add(insertInformationButton); centerPanel.add("South", insertInformationButtonPanel); cp.add("Center", centerPanel);

southPanel.setLayout(new FlowLayout(FlowLayout.RIGHT)); OKButton.setFont(new Font("Tahoma", Font.BOLD, 11)); southPanel.add(OKButton); southPanel.setBorder(BorderFactory.createEtchedBorder()); cp.add("South", southPanel); insertInformationButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { //for checking if there is a missing information if (isCorrect()) { Thread runner = new Thread() { public void run() { book = new Books(); Sumeet Dhende (2012450009) Jeet Dholakia (2012450010) Page 27

LIBRARY MANAGEMENT SYSTEM


//for checking if there is no double information in the database book.connection("SELECT BookID FROM Books WHERE ISBN = '" + data[7] + "'"); String ISBN = book.getISBN(); if (!data[7].equalsIgnoreCase(ISBN)) { try{ String sql="INSERT INTO Books (Subject,Title,Author,Publisher,Copyright," +

"Edition,Pages,ISBN,NumberOfBooks,NumberOfAvailbleBooks,Library,Availble,ShelfNo) VALUES "+ " (?,?,?,?,?,?,?,?,?,?,?,?,?)";

/*String url = "jdbc:mysql://localhost:3306/"; String dbName = "lmsDb"; String driver = "com.mysql.jdbc.Driver"; String userName = "root"; String password = "";*/ Class.forName("com.mysql.jdbc.Driver"); Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/jlibrary","root","pat123"); //Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); //Connection con=DriverManager.getConnection("jdbc:odbc:JLibrary"); PreparedStatement ps=con.prepareStatement(sql); ps.setString(1, data[0]); ps.setString(2, data[1]); Sumeet Dhende (2012450009) Jeet Dholakia (2012450010) Page 28

LIBRARY MANAGEMENT SYSTEM


ps.setString(3, data[2]); ps.setString(4, data[3]); ps.setInt(5, Integer.parseInt(data[4])); ps.setInt(6,Integer.parseInt(data[5])); ps.setInt(7, Integer.parseInt(data[6])); ps.setString(8, data[7]); ps.setInt(9, Integer.parseInt(data[8])); ps.setInt(10, Integer.parseInt(data[8])); ps.setString(11, data[9]); ps.setBoolean(12, availble); ps.setInt(13, Integer.parseInt(txtShelfNo.getText())); ps.executeUpdate(); }catch(Exception ex){ JOptionPane.showMessageDialog(null, ex.toString()); }

/*String sql="INSERT INTO Books (Subject,Title,Author,Publisher,Copyright," +

"Edition,Pages,ISBN,NumberOfBooks,NumberOfAvailbleBooks,Library,Availble,ShelfNo) VALUES ('" + data[0] + "','" + data[1] + "','" + data[2] + "','" + data[3] + "', " + data[4] + ", " + data[5] + ", " + data[6] + ", '" + data[7] + "', " + data[8] + "," + data[8] + ",'" + data[9] + "', " + availble + ", '" + txtShelfNo.getText() + "')"; book.update(sql);*/ Sumeet Dhende (2012450009) Jeet Dholakia (2012450010) Page 29

LIBRARY MANAGEMENT SYSTEM


//JOptionPane.showMessageDialog(null, sql); //for setting the array of JTextField to empty clearTextField(); } else { JOptionPane.showMessageDialog(null, "The book is in the library", "Error", JOptionPane.ERROR_MESSAGE); } } }; runner.start(); } //if there is a missing data, then display Message Dialog else { JOptionPane.showMessageDialog(null, "Please, complete the information", "Warning", JOptionPane.WARNING_MESSAGE); } } }); //for adding the action listener for the button to dispose the frame OKButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { dispose(); } }); //for setting the visible to true setVisible(true); Sumeet Dhende (2012450009) Jeet Dholakia (2012450010)

Page 30

LIBRARY MANAGEMENT SYSTEM


//show the internal frame pack(); } } AddMembers.java //import the packages for using the classes in them into the program import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class AddMembers extends JInternalFrame { //for creating the North Panel private JPanel northPanel = new JPanel(); //for creaing the North Label private JLabel northLabel = new JLabel("MEMBER INFORMATION"); //for creating the Center Panel private JPanel centerPanel = new JPanel(); //for creating an Internal Panel in the center panel private JPanel informationLabelPanel = new JPanel(); //for creating an array of JLabel private JLabel[] informationLabel = new JLabel[7]; //for creating an array of String private String[] informaionString = {" Member ID: ", " The Password: ", " Rewrite the password: ", " The Name: ", " E-MAIL: ", " Major:", " Expired: "}; Sumeet Dhende (2012450009) Jeet Dholakia (2012450010)

Page 31

LIBRARY MANAGEMENT SYSTEM


//for creating an Internal Panel in the center panel private JPanel informationTextFieldPanel = new JPanel(); //for creating an array of JTextField private JTextField[] informationTextField = new JTextField[5]; //for creating an array of JPasswordField private JPasswordField[] informationPasswordField = new JPasswordField[2]; //for creating an Internal Panel in the center panel private JPanel insertInformationButtonPanel = new JPanel(); //for creating a button private JButton insertInformationButton = new JButton("Insert the Information");

//for creating the South Panel private JPanel southPanel = new JPanel(); //for creating a button private JButton OKButton = new JButton("Exit"); //create objects from another classes for using them in the ActionListener private Members member; //for creating an array of string to store the data private String[] data; //for checking the password public boolean isPasswordCorrect() { if (informationPasswordField[0].getText().equals(informationPasswordField[1].getText())) data[1] = informationPasswordField[1].getText();

Sumeet Dhende (2012450009) Jeet Dholakia (2012450010)

Page 32

LIBRARY MANAGEMENT SYSTEM


else if (!informationPasswordField[0].getText().equals(informationPasswordField[1].getText())) return false;

return true; } //for checking the information from the text field public boolean isCorrect() { data = new String[6]; for (int i = 0; i < informationLabel.length; i++) { if (i == 0) { if (!informationTextField[i].getText().equals("")) { data[i] = informationTextField[i].getText(); } else return false; } if (i == 1 || i == 2) { if (informationPasswordField[i - 1].getText().equals("")) return false; } if (i == 3 || i == 4 || i == 5 || i == 6) { if (!informationTextField[i - 2].getText().equals("")) { data[i - 1] = informationTextField[i - 2].getText(); } Sumeet Dhende (2012450009) Jeet Dholakia (2012450010)

Page 33

LIBRARY MANAGEMENT SYSTEM


else return false; } } return true; } //for setting the array of JTextField & JPasswordField to null public void clearTextField() { for (int i = 0; i < informationLabel.length; i++) { if (i == 0) informationTextField[i].setText(null); if (i == 1 || i == 2) informationPasswordField[i - 1].setText(null); if (i == 3 || i == 4 || i == 5 || i == 6) informationTextField[i - 2].setText(null); } } //constructor of addMembers public AddMembers() { //for setting the title for the internal frame super("Add Members", false, true, false, true); //for setting the icon setFrameIcon(new ImageIcon(ClassLoader.getSystemResource("images/Add16.gif"))); //for getting the graphical user interface components display area Sumeet Dhende (2012450009) Jeet Dholakia (2012450010)

Page 34

LIBRARY MANAGEMENT SYSTEM


Container cp = getContentPane(); //for setting the layout northPanel.setLayout(new FlowLayout(FlowLayout.CENTER)); //for setting the font northLabel.setFont(new Font("Tahoma", Font.BOLD, 14)); //for adding the label to the panel northPanel.add(northLabel); //for adding the panel to the container cp.add("North", northPanel); //for setting the layout centerPanel.setLayout(new BorderLayout()); //for setting the border to the panel centerPanel.setBorder(BorderFactory.createTitledBorder("Add a new member:")); //for setting the layout informationLabelPanel.setLayout(new GridLayout(7, 1, 1, 1)); //for setting the layout informationTextFieldPanel.setLayout(new GridLayout(7, 1, 1, 1)); for (int i = 0; i < informationLabel.length; i++) { informationLabelPanel.add(informationLabel[i] = new JLabel(informaionString[i])); informationLabel[i].setFont(new Font("Tahoma", Font.BOLD, 11)); } //for adding the panel to the centerPanel centerPanel.add("West", informationLabelPanel); for (int i = 0; i < informationLabel.length; i++) { Sumeet Dhende (2012450009) Jeet Dholakia (2012450010)

Page 35

LIBRARY MANAGEMENT SYSTEM


if (i == 1 || i == 2) { informationTextFieldPanel.add(informationPasswordField[i - 1] = new JPasswordField(25)); informationPasswordField[i - 1].setFont(new Font("Tahoma", Font.PLAIN, 11)); } if (i == 0) { informationTextFieldPanel.add(informationTextField[i] = new JTextField(25)); informationTextField[i].setFont(new Font("Tahoma", Font.PLAIN, 11)); } if (i == 3 || i == 4 || i == 5 || i == 6) { informationTextFieldPanel.add(informationTextField[i - 2] = new JTextField(25)); informationTextField[i - 2].setFont(new Font("Tahoma", Font.PLAIN, 11)); } } centerPanel.add("East", informationTextFieldPanel); insertInformationButtonPanel.setLayout(new FlowLayout(FlowLayout.RIGHT)); insertInformationButton.setFont(new Font("Tahoma", Font.BOLD, 11)); insertInformationButtonPanel.add(insertInformationButton); centerPanel.add("South", insertInformationButtonPanel); cp.add("Center", centerPanel); southPanel.setLayout(new FlowLayout(FlowLayout.RIGHT)); OKButton.setFont(new Font("Tahoma", Font.BOLD, 11)); Sumeet Dhende (2012450009) Jeet Dholakia (2012450010) Page 36

LIBRARY MANAGEMENT SYSTEM


southPanel.add(OKButton); southPanel.setBorder(BorderFactory.createEtchedBorder()); cp.add("South", southPanel); insertInformationButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { //for checking if there is a missing information if (isCorrect()) { if (isPasswordCorrect()) { Thread runner = new Thread() { public void run() { member = new Members(); //for checking if there is no same information in the database member.connection("SELECT * FROM Members WHERE ID = " + data[0]); int ID = member.getID(); if (Integer.parseInt(data[0]) != ID) { member.update("INSERT INTO Members (ID,Password,Name,EMail,Major,Expired) VALUES (" + data[0] + ", '" + data[1] + "','" + data[2] + "','" + data[3] + "','" + data[4] + "','" + data[5] + "')"); //for setting the array of JTextField & JPasswordField to null clearTextField(); } Sumeet Dhende (2012450009) Jeet Dholakia (2012450010) Page 37

LIBRARY MANAGEMENT SYSTEM


else

JOptionPane.showMessageDialog(null, "Member is in the Library", "Error", JOptionPane.ERROR_MESSAGE); } }; runner.start(); } //if the password is wrong else JOptionPane.showMessageDialog(null, "the passowrd is wrong", "Error", JOptionPane.ERROR_MESSAGE); } //if there is a missing data, then display Message Dialog else JOptionPane.showMessageDialog(null, "Please, complete the information", "Warning", JOptionPane.WARNING_MESSAGE); } }); //for adding the action listener for the button to dispose the frame OKButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { dispose(); } }); //for setting the visible to true Sumeet Dhende (2012450009) Jeet Dholakia (2012450010)

Page 38

LIBRARY MANAGEMENT SYSTEM


setVisible(true); //show the internal frame pack(); } } Books.java //import the packages for using the classes in them into the program import java.sql.*; public class Books { private Connection connection = null; private Statement statement = null; private ResultSet resultSet = null; private int bookID; private String subject; private String title; private String author; private String publisher; private int copyright; private int edition; private int pages; private String ISBN; private int numberOfBooks; private int numberOfAvailbleBooks; private int numberOfBorrowedBooks; private String library; Sumeet Dhende (2012450009) Jeet Dholakia (2012450010) Page 39

LIBRARY MANAGEMENT SYSTEM


private boolean availble; private String URL = "jdbc:mysql://localhost:3306/jlibrary"; public Books() { } public int getBookID() { return bookID; } public String getSubject() { return subject; } public String getTitle() { return title; } public String getAuthor() { return author; } public String getPublisher() { return publisher; } public int getCopyright() { return copyright; } public int getEdition() { return edition; } Sumeet Dhende (2012450009) Jeet Dholakia (2012450010) Page 40

LIBRARY MANAGEMENT SYSTEM


public int getPages() { return pages; } public String getISBN() { return ISBN; } public int getNumberOfBooks() { return numberOfBooks; } public int getNumberOfAvailbleBooks() { return numberOfAvailbleBooks; } public int getNumberOfBorrowedBooks() { return numberOfBorrowedBooks; } public String getLibrary() { return library; } public boolean getAvailble() { return availble; } public void connection(String Query) { try { Class.forName("com.mysql.jdbc.Driver"); } Sumeet Dhende (2012450009) Jeet Dholakia (2012450010) Page 41

LIBRARY MANAGEMENT SYSTEM


catch (ClassNotFoundException cnfe) { System.out.println("Books.java\n" + cnfe.toString()); } catch (Exception e) { System.out.println("Books.java\n" + e.toString()); } try { connection = DriverManager.getConnection(URL,"root","pat123"); statement = connection.createStatement(); resultSet = statement.executeQuery(Query); while (resultSet.next()) { bookID = resultSet.getInt(1); subject = resultSet.getString(2); title = resultSet.getString(3); author = resultSet.getString(4); publisher = resultSet.getString(5); copyright = resultSet.getInt(6); edition = resultSet.getInt(7); pages = resultSet.getInt(8); ISBN = resultSet.getString(9); numberOfBooks = resultSet.getInt(10); numberOfAvailbleBooks = resultSet.getInt(11); numberOfBorrowedBooks = resultSet.getInt(12); library = resultSet.getString(13); availble = resultSet.getBoolean(14); Sumeet Dhende (2012450009) Jeet Dholakia (2012450010) Page 42

LIBRARY MANAGEMENT SYSTEM


} resultSet.close(); statement.close(); connection.close(); } catch (SQLException SQLe) { System.out.println("Books.java\n" + SQLe.toString()); } } public void update(String Query) { try { Class.forName("com.mysql.jdbc.Driver"); } catch (ClassNotFoundException cnfe) { System.out.println("Books.java\n" + cnfe.toString()); } catch (Exception e) { System.out.println("Books.java\n" + e.toString()); } try { //connection = DriverManager.getConnection("jdbc:odbc:JLibrary2"); connection = DriverManager.getConnection(URL,"root","pat123"); statement = connection.createStatement(); statement.executeUpdate(Query); statement.close(); Sumeet Dhende (2012450009) Jeet Dholakia (2012450010) Page 43

LIBRARY MANAGEMENT SYSTEM


connection.close(); } catch (SQLException SQLe) { System.out.println("Books.java\nError:" + SQLe.toString()); } } } Borrow.java //import the packages for using the classes in them into the program import java.sql.*; public class Borrow { private Connection connection = null; private Statement statement = null; private ResultSet resultSet = null; private int bookID; private int memberID; private Date dayOfBorrowed; private Date dayOfReturn; private String URL = "jdbc:mysql://localhost:3306/jlibrary"; public Borrow() { } public int getBookID() { return bookID; } public int getMemberID() { Sumeet Dhende (2012450009) Jeet Dholakia (2012450010) Page 44

LIBRARY MANAGEMENT SYSTEM


return memberID; } public Date getDayOfBorrowed() { return dayOfBorrowed; } public Date getDayOfReturn() { return dayOfReturn; }

public void connection() { try { Class.forName("com.mysql.jdbc.Driver"); } catch (ClassNotFoundException cnfe) { System.out.println("Borrow.java\n" + cnfe.toString()); } catch (Exception e) { System.out.println("Borrow.java\n" + e.toString()); } try { connection = DriverManager.getConnection(URL,"root","pat123"); statement = connection.createStatement(); resultSet = statement.executeQuery("SELECT * FROM Borrow"); while (resultSet.next()) { bookID = resultSet.getInt(1); Sumeet Dhende (2012450009) Jeet Dholakia (2012450010) Page 45

LIBRARY MANAGEMENT SYSTEM


memberID = resultSet.getInt(2); dayOfBorrowed = resultSet.getDate(3); dayOfReturn = resultSet.getDate(4); } resultSet.close(); statement.close(); connection.close(); } catch (SQLException SQLe) { System.out.println("Borrow.java\n" + SQLe.toString()); } } public void update(String Query) { try { Class.forName("com.mysql.jdbc.Driver"); } catch (ClassNotFoundException cnfe) { System.out.println("Borrow.java\n" + cnfe.toString()); } catch (Exception e) { System.out.println("Borrow.java\n" + e.toString()); } try { connection = DriverManager.getConnection(URL,"root","pat123"); statement = connection.createStatement(); Sumeet Dhende (2012450009) Jeet Dholakia (2012450010) Page 46

LIBRARY MANAGEMENT SYSTEM


statement.executeUpdate(Query); statement.close(); connection.close(); } catch (SQLException SQLe) { System.out.println("Borrow.java\n" + SQLe.toString()); } } } Login.java import java.awt.EventQueue; public class login extends javax.swing.JFrame { public login() { initComponents(); } @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GENBEGIN:initComponents private void initComponents() { jLabel1 = new javax.swing.JLabel(); jLabel2 = new javax.swing.JLabel(); jTextField1 = new javax.swing.JTextField(); jButton1 = new javax.swing.JButton(); jPasswordField1 = new javax.swing.JPasswordField(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); Sumeet Dhende (2012450009) Jeet Dholakia (2012450010)

Page 47

LIBRARY MANAGEMENT SYSTEM


setTitle("LOGIN"); setResizable(false); jLabel1.setText("USERNAME"); jLabel2.setText("PASSWORD"); jTextField1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jTextField1ActionPerformed(evt); } }); jButton1.setText("LOGIN"); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); } }); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup()

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(78, 78, 78)

Sumeet Dhende (2012450009) Jeet Dholakia (2012450010)

Page 48

LIBRARY MANAGEMENT SYSTEM


.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addGap(57, 57, 57)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(jTextField1, javax.swing.GroupLayout.DEFAULT_SIZE, 124, Short.MAX_VALUE) .addComponent(jPasswordField1))) .addGroup(layout.createSequentialGroup() .addGap(136, 136, 136) .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE))) .addContainerGap(84, Short.MAX_VALUE)) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(115, 115, 115)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) Sumeet Dhende (2012450009) Jeet Dholakia (2012450010)

Page 49

LIBRARY MANAGEMENT SYSTEM


.addGap(18, 18, 18)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel2) .addGroup(layout.createSequentialGroup() .addComponent(jPasswordField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18) .addComponent(jButton1))) .addContainerGap(81, Short.MAX_VALUE)) ); pack(); setLocationRelativeTo(null); }// </editor-fold>//GEN-END:initComponents private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {//GENFIRST:event_jTextField1ActionPerformed // TODO add your handling code here: }//GEN-LAST:event_jTextField1ActionPerformed private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GENFIRST:event_jButton1ActionPerformed if(jTextField1.getText().equals("admin") && jPasswordField1.getText().equals("admin")) { //m =new Main(this); //m.setVisible(true); EventQueue.invokeLater(new Main(new JLibrary()));

Sumeet Dhende (2012450009) Jeet Dholakia (2012450010)

Page 50

LIBRARY MANAGEMENT SYSTEM

} }//GEN-LAST:event_jButton1ActionPerformed public static void main(String args[]) { try { for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { javax.swing.UIManager.setLookAndFeel(info.getClassName()); break; } } } catch (ClassNotFoundException ex) {

java.util.logging.Logger.getLogger(login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) {

java.util.logging.Logger.getLogger(login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) {

java.util.logging.Logger.getLogger(login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) {

java.util.logging.Logger.getLogger(login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); Sumeet Dhende (2012450009) Jeet Dholakia (2012450010)

Page 51

LIBRARY MANAGEMENT SYSTEM


} //</editor-fold>

/* Create and display the form */ java.awt.EventQueue.invokeLater(new Runnable() { public void run() {

new login().setVisible(true); } }); } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton jButton1; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JPasswordField jPasswordField1; private javax.swing.JTextField jTextField1; // End of variables declaration//GEN-END:variables } Main.java //import the packages for using the classes in them into the program import java.awt.EventQueue; import java.awt.Frame; import javax.swing.JDialog; public class Main implements Runnable { Sumeet Dhende (2012450009) Jeet Dholakia (2012450010) Page 52

LIBRARY MANAGEMENT SYSTEM


final Frame frame; public Main(Frame frame) { this.frame = frame; } public void run() { frame.show(); } public static void main(String[] args) { JDialog.setDefaultLookAndFeelDecorated(true); // Throw a nice little title page up on the screen first new Splash().showSplash(3000); new login().setVisible(true); //EventQueue.invokeLater(new Main(new JLibrary())); } } Members.java //import the packages for using the classes in them into the program import java.sql.*; public class Members { private Connection connection = null; private Statement statement = null; private ResultSet resultSet = null; private int memberID; private int ID; private String password; Sumeet Dhende (2012450009) Jeet Dholakia (2012450010) Page 53

LIBRARY MANAGEMENT SYSTEM


private String name; private String email; private String major; private int numberOfBooks; private int mony; private Date expired; private String URL = "jdbc:mysql://localhost:3306/jlibrary"; public Members() { } /*public Members(int memberID, int ID, String password, String name, String email, String major, int numberOfBooks, int mony, Date expired) { this.memberID = memberID; this.ID = ID; this.password = password; this.name = name; this.email = email; this.major = major; this.numberOfBooks = numberOfBooks; this.mony = mony; this.expired = expired; }*/ public int getMemberID() { return memberID; }

Sumeet Dhende (2012450009) Jeet Dholakia (2012450010)

Page 54

LIBRARY MANAGEMENT SYSTEM


public int getID() { return ID; } public String getPassword() { return password; } public String getName() { return name; } public String getEmail() { return email; } public String getMajor() { return major; } public int getNumberOfBooks() { return numberOfBooks; }

public int getMony() { return mony; } public Date getExpired() { return expired; } Sumeet Dhende (2012450009) Jeet Dholakia (2012450010) Page 55

LIBRARY MANAGEMENT SYSTEM


public void connection(String Query) { try { Class.forName("com.mysql.jdbc.Driver"); } catch (ClassNotFoundException cnfe) { System.out.println("Members.java\n" + cnfe.toString()); } catch (Exception e) { System.out.println("Members.java\n" + e.toString()); } try { connection = DriverManager.getConnection(URL,"root","pat123"); statement = connection.createStatement(); resultSet = statement.executeQuery(Query); while (resultSet.next()) { memberID = resultSet.getInt(1); ID = resultSet.getInt(2); password = resultSet.getString(3); name = resultSet.getString(4); email = resultSet.getString(5); major = resultSet.getString(6); numberOfBooks = resultSet.getInt(7); mony = resultSet.getInt(8); expired = resultSet.getDate(9); } Sumeet Dhende (2012450009) Jeet Dholakia (2012450010) Page 56

LIBRARY MANAGEMENT SYSTEM


resultSet.close(); statement.close(); connection.close(); } catch (SQLException SQLe) { System.out.println("Members.java\n" + SQLe.toString()); } }

public void update(String Query) { try { Class.forName("com.mysql.jdbc.Driver"); } catch (ClassNotFoundException cnfe) { System.out.println("Members.java\n" + cnfe.toString()); } catch (Exception e) { System.out.println("Members.java\n" + e.toString()); } try { connection = DriverManager.getConnection(URL,"root","pat123"); statement = connection.createStatement(); statement.executeUpdate(Query); statement.close(); connection.close(); Sumeet Dhende (2012450009) Jeet Dholakia (2012450010) Page 57

LIBRARY MANAGEMENT SYSTEM


} catch (SQLException SQLe) { System.out.println("Members.java\n" + SQLe.toString()); } } } Splash.java //import the packages for using the classes in them into the program import javax.swing.*; import java.awt.*; public class Splash { // A simple little method to show a title screen in the // center of the screen for a given amount of time. public void showSplash(int duration) { JWindow splash = new JWindow(); JPanel content = (JPanel) splash.getContentPane(); // set the window's bounds, centering the window int width = 354; int height = 268; Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); int x = (screen.width - width) / 2; int y = (screen.height - height) / 2; splash.setBounds(x, y, width, height); // build the splash screen

Sumeet Dhende (2012450009) Jeet Dholakia (2012450010)

Page 58

LIBRARY MANAGEMENT SYSTEM


JLabel label = new JLabel(new ImageIcon(ClassLoader.getSystemResource("images/splash.JPG"))); JLabel copyrt = new JLabel("", JLabel.CENTER); copyrt.setFont(new Font("Tahoma", Font.BOLD, 10)); //copyrt.setBorder(BorderFactory.createEtchedBorder()); content.setBackground(Color.LIGHT_GRAY); //content.setBackground(new Color(232, 232, 228)); content.add(label, BorderLayout.CENTER); content.add(copyrt, BorderLayout.SOUTH); content.setBorder(BorderFactory.createLineBorder(Color.BLACK, 2)); // display it splash.setVisible(true); // Wait a little while, maybe while loading resources try { Thread.sleep(duration); } catch (Exception e) { } splash.setVisible(false); } } Menubar.java //import the packages for using the classes in them into the program import javax.swing.*; import java.awt.event.ActionEvent; import java.awt.event.KeyEvent; Sumeet Dhende (2012450009) Jeet Dholakia (2012450010)

Page 59

LIBRARY MANAGEMENT SYSTEM


import javax.management.JMException; public class Menubar extends JMenuBar { //for creating the JMenu for the program public JMenu fileMenu, bookMenu, memberMenu, searchMenu, loanMenu, reserveMenu, helpMenu; //for creating the JMenuItem for JMenu public JMenuItem printBook, exit, addBook, listBook, listAvailbleBook, listBorrowedBook; public JMenuItem editBook, removeBook, bookInformation, addMember, listMember, editMember; public JMenuItem removeMember, memberInformation, searchBooksAndMembers, borrowBook, returnBook; public JMenuItem listissuedbooks,reserveBook, help, about; //for creating an imageIcon public ImageIcon[] icons; //for creating the name of the image file 16*16 public String[] imageName16 = {"images/Print16.gif", "images/Exit16.gif", "images/Add16.gif", "images/List16.gif", "images/Edit16.gif", "images/Delete16.gif", "images/Information16.gif", "images/Find16.gif", "images/Export16.gif", "images/Import16.gif", "images/Help16.gif", "images/About16.gif" }; public Menubar() { //for adding book, member, search, loan & help Menus to the menu bar this.add(fileMenu = new JMenu("File")); Sumeet Dhende (2012450009) Jeet Dholakia (2012450010)

Page 60

LIBRARY MANAGEMENT SYSTEM


this.add(bookMenu = new JMenu("Books")); this.add(memberMenu = new JMenu("Members")); this.add(searchMenu = new JMenu("Search")); this.add(loanMenu = new JMenu("Loan")); this.add(reserveMenu = new JMenu("Reserve")); this.add(helpMenu = new JMenu("Help")); fileMenu.setMnemonic('f'); bookMenu.setMnemonic('b'); memberMenu.setMnemonic('m'); searchMenu.setMnemonic('s'); loanMenu.setMnemonic('l'); reserveMenu.setMnemonic('r'); helpMenu.setMnemonic('h'); //for setting the image icons icons = new ImageIcon[12]; for (int i = 0; i < imageName16.length; i++) { icons[i] = new ImageIcon(ClassLoader.getSystemResource(imageName16[i])); } //for adding print books & exit fileMenu.add(printBook = new JMenuItem("Print Books", icons[0])); fileMenu.add(exit = new JMenuItem("Exit", icons[1])); //for adding add, list, listAvailble, listBorrowed, edit & remove Books and book information to the bookMenu bookMenu.add(addBook = new JMenuItem("Add Book", icons[2])); bookMenu.add(listBook = new JMenuItem("List All Books", icons[3])); Sumeet Dhende (2012450009) Jeet Dholakia (2012450010)

Page 61

LIBRARY MANAGEMENT SYSTEM


bookMenu.add(listAvailbleBook = new JMenuItem("List Availble Books", icons[3])); bookMenu.add(listBorrowedBook = new JMenuItem("List Borrowed Books", icons[3])); bookMenu.add(editBook = new JMenuItem("Edit Books", icons[4])); bookMenu.add(removeBook = new JMenuItem("Remove Book", icons[5])); //bookMenu.add(bookInformation = new JMenuItem("Book Information", icons[6])); //for adding add, list, edit & remove Members and member information to the memberMenu memberMenu.add(addMember = new JMenuItem("Add Member", icons[2])); memberMenu.add(listMember = new JMenuItem("List All Members", icons[3])); memberMenu.add(editMember = new JMenuItem("Edit Members", icons[4])); memberMenu.add(removeMember = new JMenuItem("Remove Member", icons[5])); memberMenu.add(memberInformation = new JMenuItem("Member Information", icons[6])); //for adding add, list & remove Members to the memberMenu searchMenu.add(searchBooksAndMembers = new JMenuItem("Search", icons[7])); //for adding borrow & return books to the loanMenu loanMenu.add(borrowBook = new JMenuItem("Borrow a Book", icons[8])); loanMenu.add(returnBook = new JMenuItem("Return a Book", icons[9])); loanMenu.add(listissuedbooks=new JMenuItem("Issued book details",icons[3])); //Reserve a book reserveMenu.add(reserveBook = new JMenuItem("Reserve a Book", icons[10])); //for adding help & about to the helpMenu helpMenu.add(help = new JMenuItem("Help", icons[10])); helpMenu.add(about = new JMenuItem("About", icons[11])); //for setting the shortcut

Sumeet Dhende (2012450009) Jeet Dholakia (2012450010)

Page 62

LIBRARY MANAGEMENT SYSTEM


printBook.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_P, ActionEvent.CTRL_MASK)); exit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F4, ActionEvent.ALT_MASK)); searchBooksAndMembers.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, ActionEvent.CTRL_MASK)); addBook.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A, ActionEvent.CTRL_MASK)); listBook.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_L, ActionEvent.CTRL_MASK)); editBook.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_E, ActionEvent.CTRL_MASK)); removeBook.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V, ActionEvent.CTRL_MASK)); addMember.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_M, ActionEvent.CTRL_MASK)); listMember.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_I, ActionEvent.CTRL_MASK)); editMember.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_D, ActionEvent.CTRL_MASK)); removeMember.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R, ActionEvent.CTRL_MASK)); borrowBook.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_B, ActionEvent.CTRL_MASK)); returnBook.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R, ActionEvent.CTRL_MASK));

listissuedbooks.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X,ActionEvent.CTRL_ MASK)); help.setAccelerator(KeyStroke.getKeyStroke("F1")); Sumeet Dhende (2012450009) Jeet Dholakia (2012450010)

Page 63

LIBRARY MANAGEMENT SYSTEM


about.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_T, ActionEvent.CTRL_MASK)); } } PrintBooks.java //import the packages for using the classes in them into the program import javax.swing.*; import java.awt.*; import java.awt.print.PageFormat; import java.awt.print.Printable; import java.awt.print.PrinterException; import java.sql.*; import java.util.StringTokenizer; import java.util.Vector; public class PrintingBooks extends JInternalFrame implements Printable { //for setting the connection and statement private Connection connection = null; private Statement statement = null; private ResultSet resultset = null;

private String URL = "jdbc:mysql://localhost:3306/jlibrary"; //for creating the text area private JTextArea textArea = new JTextArea(); //for creating the vector to use it in the print private Vector lines; Sumeet Dhende (2012450009) Jeet Dholakia (2012450010)

Page 64

LIBRARY MANAGEMENT SYSTEM


public static final int TAB_SIZE = 5; //constructor of JLibrary public PrintingBooks(String query) { super("Printing Books", false, true, false, true); //for getting the graphical user interface components display area Container cp = getContentPane(); //for setting the font textArea.setFont(new Font("Tahoma", Font.PLAIN, 9)); //for adding the textarea to the container cp.add(textArea); try { Class.forName("com.mysql.jdbc.Driver"); } catch (ClassNotFoundException ea) { System.out.println(ea.toString()); } catch (Exception e) { System.out.println(e.toString()); } try { connection = DriverManager.getConnection(URL); statement = connection.createStatement(); resultset = statement.executeQuery(query); textArea.append("=============== Books Information ===============\n\n"); Sumeet Dhende (2012450009) Jeet Dholakia (2012450010)

Page 65

LIBRARY MANAGEMENT SYSTEM


while (resultset.next()) { textArea.append("Subject: " + resultset.getString("Subject") + "\n" + "Title: " + resultset.getString("Title") + "\n" + "Author(s): " + resultset.getString("Author") + "\n" + "Copyright: " + resultset.getString("Copyright") + "\n" + "Edition: " + resultset.getString("Edition") + "\n" + "ISBN: " + resultset.getString("ISBN") + "\n" + "Library: " + resultset.getString("Library") + "\n\n"); } textArea.append("=============== Books Information ==============="); resultset.close(); statement.close(); connection.close(); } catch (SQLException SQLe) { System.out.println(SQLe.toString()); } //for setting the visible to true setVisible(true); //to show the frame pack(); } public int print(Graphics pg, PageFormat pageFormat, int pageIndex) throws PrinterException { Sumeet Dhende (2012450009) Jeet Dholakia (2012450010) Page 66

LIBRARY MANAGEMENT SYSTEM


pg.translate((int) pageFormat.getImageableX(), (int) pageFormat.getImageableY()); int wPage = (int) pageFormat.getImageableWidth(); int hPage = (int) pageFormat.getImageableHeight(); pg.setClip(0, 0, wPage, hPage); pg.setColor(textArea.getBackground()); pg.fillRect(0, 0, wPage, hPage); pg.setColor(textArea.getForeground()); Font font = textArea.getFont(); pg.setFont(font); FontMetrics fm = pg.getFontMetrics(); int hLine = fm.getHeight(); if (lines == null) lines = getLines(fm, wPage); int numLines = lines.size(); int linesPerPage = Math.max(hPage / hLine, 1); int numPages = (int) Math.ceil((double) numLines / (double) linesPerPage); if (pageIndex >= numPages) { lines = null; return NO_SUCH_PAGE; } int x = 0; int y = fm.getAscent(); int lineIndex = linesPerPage * pageIndex; while (lineIndex < lines.size() && y < hPage) { Sumeet Dhende (2012450009) Jeet Dholakia (2012450010)

Page 67

LIBRARY MANAGEMENT SYSTEM


String str = (String) lines.get(lineIndex); pg.drawString(str, x, y); y += hLine; lineIndex++; } return PAGE_EXISTS; }

protected Vector getLines(FontMetrics fm, int wPage) { Vector v = new Vector(); String text = textArea.getText(); String prevToken = ""; StringTokenizer st = new StringTokenizer(text, "\n\r", true); while (st.hasMoreTokens()) { String line = st.nextToken(); if (line.equals("\r")) continue; // StringTokenizer will ignore empty lines, so it's a bit tricky to get them... if (line.equals("\n") && prevToken.equals("\n")) v.add(""); prevToken = line; if (line.equals("\n")) continue;

StringTokenizer st2 = new StringTokenizer(line, " \t", true); Sumeet Dhende (2012450009) Jeet Dholakia (2012450010) Page 68

LIBRARY MANAGEMENT SYSTEM


String line2 = ""; while (st2.hasMoreTokens()) { String token = st2.nextToken(); if (token.equals("\t")) { int numSpaces = TAB_SIZE - line2.length() % TAB_SIZE; token = ""; for (int k = 0; k < numSpaces; k++) token += " "; } int lineLength = fm.stringWidth(line2 + token); if (lineLength > wPage && line2.length() > 0) { v.add(line2); line2 = token.trim(); continue; } line2 += token; } v.add(line2); } return v; } }

Sumeet Dhende (2012450009) Jeet Dholakia (2012450010)

Page 69

LIBRARY MANAGEMENT SYSTEM


ResultSetTableModel.java import javax.swing.table.AbstractTableModel; import java.sql.*; public class ResultSetTableModel extends AbstractTableModel { private Connection connection; private Statement statement; private ResultSet resultSet; private ResultSetMetaData metaData; private int numberOfRows; // keep track of database connection status private boolean connectedToDatabase = false; // initialize resultSet and obtain its meta data object; // determine number of rows public ResultSetTableModel(String driver, String url, String query) throws SQLException, ClassNotFoundException { Class.forName(driver); // load database driver class connection = DriverManager.getConnection(url,"root","pat123"); // connect to database // create Statement to query database statement = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); connectedToDatabase = true; // update database connection status setQuery(query); // set query and execute it }

Sumeet Dhende (2012450009) Jeet Dholakia (2012450010)

Page 70

LIBRARY MANAGEMENT SYSTEM


// get class that represents column type public Class getColumnClass(int column) throws IllegalStateException { // ensure database connection is available if (!connectedToDatabase) throw new IllegalStateException("Not Connected to Database"); // determine Java class of column try { String className = metaData.getColumnClassName(column + 1); return Class.forName(className); // return Class object that represents className } // catch SQLExceptions and ClassNotFoundExceptions catch (Exception exception) { exception.printStackTrace(); } // if problems occur above, assume type Object return Object.class; } // get number of columns in ResultSet public int getColumnCount() throws IllegalStateException { // ensure database connection is available if (!connectedToDatabase) throw new IllegalStateException("Not Connected to Database"); // determine number of columns try { return metaData.getColumnCount(); Sumeet Dhende (2012450009) Jeet Dholakia (2012450010) Page 71

LIBRARY MANAGEMENT SYSTEM


} // catch SQLExceptions and print error message catch (SQLException sqlException) { sqlException.printStackTrace(); } // if problems occur above, return 0 for number of columns return 0; } // get name of a particular column in ResultSet public String getColumnName(int column) throws IllegalStateException { // ensure database connection is available if (!connectedToDatabase) throw new IllegalStateException("Not Connected to Database"); // determine column name try { return metaData.getColumnName(column + 1); } // catch SQLExceptions and print error message catch (SQLException sqlException) { sqlException.printStackTrace(); } // if problems, return empty string for column name return ""; }

Sumeet Dhende (2012450009) Jeet Dholakia (2012450010)

Page 72

LIBRARY MANAGEMENT SYSTEM


// return number of rows in ResultSet public int getRowCount() throws IllegalStateException { // ensure database connection is available if (!connectedToDatabase) throw new IllegalStateException("Not Connected to Database"); return numberOfRows; } // obtain value in particular row and column public Object getValueAt(int row, int column) throws IllegalStateException { // ensure database connection is available if (!connectedToDatabase) throw new IllegalStateException("Not Connected to Database"); // obtain a value at specified ResultSet row and column try { resultSet.absolute(row + 1); return resultSet.getObject(column + 1); } // catch SQLExceptions and print error message catch (SQLException sqlException) { sqlException.printStackTrace(); } // if problems, return empty string object return ""; }

Sumeet Dhende (2012450009) Jeet Dholakia (2012450010)

Page 73

LIBRARY MANAGEMENT SYSTEM


// set new database query string public void setQuery(String query) throws SQLException, IllegalStateException { // ensure database connection is available if (!connectedToDatabase) throw new IllegalStateException("Not Connected to Database"); // specify query and execute it resultSet = statement.executeQuery(query); // obtain meta data for ResultSet metaData = resultSet.getMetaData(); // determine number of rows in ResultSet resultSet.last(); // move to last row numberOfRows = resultSet.getRow(); // get row number fireTableStructureChanged(); // notify JTable that model has changed } // close Statement and Connection public void disconnectFromDatabase() { // close Statement and Connection try { statement.close(); connection.close(); } // catch SQLExceptions and print error message catch (SQLException sqlException) { sqlException.printStackTrace(); } Sumeet Dhende (2012450009) Jeet Dholakia (2012450010)

Page 74

LIBRARY MANAGEMENT SYSTEM


// update database connection status finally { connectedToDatabase = false; } } } // end class ResultSetTableModel MembersInformation.java //import the packages for using the classes in them into the program import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; //for creating the North Panel private JPanel northPanel = new JPanel(); //for creaing the North Label private JLabel northLabel = new JLabel("MEMBER INFORMATION"); //for creating the Center Panel private JPanel centerPanel = new JPanel(); //for creating the edit Panel private JPanel memberIDPanel = new JPanel(); //for creating the edit information Panel private JPanel memberIDInformationPanel = new JPanel(); //for creating the edit label panel private JPanel memberIDInformationLabelPanel = new JPanel(); //for creating the edit textField panel Sumeet Dhende (2012450009) Jeet Dholakia (2012450010) Page 75

LIBRARY MANAGEMENT SYSTEM


private JPanel memberIDInformationTextFieldPanel = new JPanel(); //for creating the edit button panel private JPanel memberIDButtonPanel = new JPanel(); //for creating the label private JLabel memberIDLabel = new JLabel("MemberID: "); //for creating the textField private JTextField memberIDTextField = new JTextField(25); //for creating the button private JButton memberIDButton = new JButton("OK"); //for creating the information Panel private JPanel informationPanel = new JPanel(); //for creating an Internal Panel in the center panel private JPanel informationLabelPanel = new JPanel(); //for creating an array of JLabel private JLabel[] informationLabel = new JLabel[7]; //for creating an array of String private String[] informaionString = {" Member ID: ", " The Password: ", " Rewrite the password: ", " The Name: ", " E-MAIL: ", " Major:", " Expired: "}; //for creating an Internal Panel in the center panel private JPanel informationTextFieldPanel = new JPanel(); //for creating an array of JTextField private JTextField[] informationTextField = new JTextField[5]; //for creating an array of JPasswordField private JPasswordField[] informationPasswordField = new JPasswordField[2]; Sumeet Dhende (2012450009) Jeet Dholakia (2012450010)

Page 76

LIBRARY MANAGEMENT SYSTEM


//for creating an Internal Panel in the center panel private JPanel InformationButtonPanel = new JPanel(); //for creating a button private JButton fButton = new JButton(">"); //for creating the South Panel private JPanel southPanel = new JPanel(); //for creating a button private JButton exitButton = new JButton("Exit"); //create objects from another classes for using them in the ActionListener private Members member; //for creating an array of string to store the data private String[] data; //for checking the password public boolean isPasswordCorrect() { if (informationPasswordField[0].getText().equals(informationPasswordField[1].getText())) data[1] = informationPasswordField[0].getText(); else if (!informationPasswordField[0].getText().equals(informationPasswordField[1].getText())) return false;

return true; } //for checking the information from the text field public boolean isCorrect() { Sumeet Dhende (2012450009) Jeet Dholakia (2012450010)

Page 77

LIBRARY MANAGEMENT SYSTEM


data = new String[6]; for (int i = 0; i < informationLabel.length; i++) { if (i == 0) { if (!informationTextField[i].getText().equals("")) { data[i] = informationTextField[i].getText(); } else return false; } if (i == 1 || i == 2) { if (informationPasswordField[i - 1].getText().equals("")) return false; } if (i == 3 || i == 4 || i == 5 || i == 6) { if (!informationTextField[i - 2].getText().equals("")) { data[i - 1] = informationTextField[i - 2].getText(); } else return false; } } return true; } //for checking the information from the text field public boolean isEditCorrect() { Sumeet Dhende (2012450009) Jeet Dholakia (2012450010) Page 78

LIBRARY MANAGEMENT SYSTEM


if (memberIDTextField.getText().equals("")) return false; return true; } //for setting the array of JTextField & JPasswordField to null public void clearTextField() { memberIDTextField.setText(null); for (int i = 0; i < informationLabel.length; i++) { if (i == 0) informationTextField[i].setText(null); if (i == 1 || i == 2) informationPasswordField[i - 1].setText(null); if (i == 3 || i == 4 || i == 5 || i == 6) informationTextField[i - 2].setText(null); } } //constructor of addMembers public MembersInformation() { //for setting the title for the internal frame super("Members Information", false, true, false, true); //for setting the icon setFrameIcon(new ImageIcon(ClassLoader.getSystemResource("images/Information16.gif"))); //for getting the graphical user interface components display area Container cp = getContentPane(); Sumeet Dhende (2012450009) Jeet Dholakia (2012450010)

Page 79

LIBRARY MANAGEMENT SYSTEM


//for setting the layout northPanel.setLayout(new FlowLayout(FlowLayout.CENTER)); //for setting the font northLabel.setFont(new Font("Tahoma", Font.BOLD, 14)); //for adding the label to the panel northPanel.add(northLabel); //for adding the panel to the container cp.add("North", northPanel); //for setting the layout centerPanel.setLayout(new BorderLayout()); //for setting the layout memberIDPanel.setLayout(new BorderLayout()); //for setting the border to the panel memberIDPanel.setBorder(BorderFactory.createTitledBorder("MemberID: ")); //for setting the layout memberIDInformationPanel.setLayout(new BorderLayout()); //for setting the layout memberIDInformationLabelPanel.setLayout(new GridLayout(1, 1, 1, 1)); //for adding the label to the panel memberIDInformationLabelPanel.add(memberIDLabel); //for setting the font to the label memberIDLabel.setFont(new Font("Tahoma", Font.BOLD, 11)); //for adding the editInformationLabelPanel to the editInformationLabel memberIDInformationPanel.add("West", memberIDInformationLabelPanel); //for setting the layout Sumeet Dhende (2012450009) Jeet Dholakia (2012450010) Page 80

LIBRARY MANAGEMENT SYSTEM


memberIDInformationTextFieldPanel.setLayout(new GridLayout(1, 1, 1, 1)); //for adding the textField to the panel memberIDInformationTextFieldPanel.add(memberIDTextField); //for setting the font to the textField memberIDTextField.setFont(new Font("Tahoma", Font.PLAIN, 11)); //for adding the editInformationTextField to the editInformationPanel memberIDInformationPanel.add("East", memberIDInformationTextFieldPanel); //for adding the editInformationPanel to the editPanel memberIDPanel.add("North", memberIDInformationPanel); //for setting the layout memberIDButtonPanel.setLayout(new FlowLayout(FlowLayout.RIGHT)); //for adding the button to the panel memberIDButtonPanel.add(memberIDButton); //for setting the fonr to the button memberIDButton.setFont(new Font("Tahoma", Font.BOLD, 11)); //for adding the editInformationButtonPanel to the editPanel memberIDPanel.add("Center", memberIDButtonPanel); //for adding the editPanel to the centerPanel centerPanel.add("North", memberIDPanel); //for setting the layout informationPanel.setLayout(new BorderLayout()); //for setting the border to the panel informationPanel.setBorder(BorderFactory.createTitledBorder("Edit a member: ")); //for setting the layout Sumeet Dhende (2012450009) Jeet Dholakia (2012450010)

Page 81

LIBRARY MANAGEMENT SYSTEM


informationLabelPanel.setLayout(new GridLayout(7, 1, 1, 1)); //for setting the layout informationTextFieldPanel.setLayout(new GridLayout(7, 1, 1, 1)); for (int i = 0; i < informationLabel.length; i++) { informationLabelPanel.add(informationLabel[i] = new JLabel(informaionString[i])); informationLabel[i].setFont(new Font("Tahoma", Font.BOLD, 11)); } //for adding the panel to the centerPanel informationPanel.add("West", informationLabelPanel); for (int i = 0; i < informationLabel.length; i++) { if (i == 1 || i == 2) { informationTextFieldPanel.add(informationPasswordField[i - 1] = new JPasswordField(25)); informationPasswordField[i - 1].setFont(new Font("Tahoma", Font.PLAIN, 11)); informationPasswordField[i - 1].setEnabled(false); } if (i == 0) { informationTextFieldPanel.add(informationTextField[i] = new JTextField(25)); informationTextField[i].setFont(new Font("Tahoma", Font.PLAIN, 11)); informationTextField[i].setEditable(false); } if (i == 3 || i == 4 || i == 5 || i == 6) {

Sumeet Dhende (2012450009) Jeet Dholakia (2012450010)

Page 82

LIBRARY MANAGEMENT SYSTEM


informationTextFieldPanel.add(informationTextField[i - 2] = new JTextField(25)); informationTextField[i - 2].setFont(new Font("Tahoma", Font.PLAIN, 11)); informationTextField[i - 2].setEditable(false); } } informationPanel.add("East", informationTextFieldPanel); InformationButtonPanel.setLayout(new FlowLayout(FlowLayout.RIGHT)); fButton.setFont(new Font("Tahoma", Font.BOLD, 11)); InformationButtonPanel.add(fButton); informationPanel.add("South", InformationButtonPanel); centerPanel.add("Center", informationPanel); cp.add("Center", centerPanel); southPanel.setLayout(new FlowLayout(FlowLayout.RIGHT)); exitButton.setFont(new Font("Tahoma", Font.BOLD, 11)); southPanel.add(exitButton); southPanel.setBorder(BorderFactory.createEtchedBorder()); cp.add("South", southPanel);

//for adding the action listener for the button to dispose the frame exitButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { dispose(); } Sumeet Dhende (2012450009) Jeet Dholakia (2012450010)

Page 83

LIBRARY MANAGEMENT SYSTEM


}); //for setting the visible to true setVisible(true); //show the internal frame pack(); } } RemoveBooks.java //import the packages for using the classes in them into the program import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; //for creating the North Panel private JPanel northPanel = new JPanel(); //for creating the label private JLabel title = new JLabel("BOOK INFORMATION"); //for creating the Center Panel private JPanel centerPanel = new JPanel(); //for creating an Internal Panel in the center panel private JPanel removePanel = new JPanel(); //for creating the label private JLabel removeLabel = new JLabel(" Write the Book ID: "); //for creating the text field private JTextField removeTextField = new JTextField(); Sumeet Dhende (2012450009) Jeet Dholakia (2012450010) Page 84

LIBRARY MANAGEMENT SYSTEM


//for creating string to store the data private String data; //for creating an Internal Panel in the center panel private JPanel removeMemberPanel = new JPanel(); //for creating the button private JButton removeButton = new JButton("Remove"); //for creating the South Panel private JPanel southPanel = new JPanel(); //for adding the button private JButton exitButton = new JButton("Exit"); //create objects from another classes for using them in the ActionListener private Books book; //for checking the information from the text field public boolean isCorrect() { if (!removeTextField.getText().equals("")) { data = removeTextField.getText(); return true; } else return false; }

//constructor of removeBooks public RemoveBooks() { //for setting the title for the internal frame Sumeet Dhende (2012450009) Jeet Dholakia (2012450010) Page 85

LIBRARY MANAGEMENT SYSTEM


super("Remove Books", false, true, false, true); //for setting the icon setFrameIcon(new ImageIcon(ClassLoader.getSystemResource("images/Delete16.gif"))); //for getting the graphical user interface components display area Container cp = getContentPane(); //for setting the layout northPanel.setLayout(new FlowLayout(FlowLayout.CENTER)); //for setting the font title.setFont(new Font("Tahoma", Font.BOLD, 14)); //for adding the label northPanel.add(title); //for adding the panel to the container cp.add("North", northPanel); //for setting the layout centerPanel.setLayout(new BorderLayout()); //for setting the layout removePanel.setLayout(new GridLayout(1, 2, 1, 1)); //for adding the label removePanel.add(removeLabel); //for adding the text field removePanel.add(removeTextField); //for adding the internal panel to the panel centerPanel.add("Center", removePanel);

Sumeet Dhende (2012450009) Jeet Dholakia (2012450010)

Page 86

LIBRARY MANAGEMENT SYSTEM


//for setting the layout removeMemberPanel.setLayout(new FlowLayout(FlowLayout.RIGHT)); //for adding the button removeMemberPanel.add(removeButton); //for addint the internal panel to the center panel centerPanel.add("South", removeMemberPanel); //for setting the border centerPanel.setBorder(BorderFactory.createTitledBorder("Remove a book:")); //for adding the center panel to the container cp.add("Center", centerPanel); removeLabel.setFont(new Font("Tahoma", Font.BOLD, 11)); removeTextField.setFont(new Font("Tahoma", Font.PLAIN, 11)); exitButton.setFont(new Font("Tahoma", Font.BOLD, 11)); removeButton.setFont(new Font("Tahoma", Font.BOLD, 11)); //for setting the layout southPanel.setLayout(new FlowLayout(FlowLayout.RIGHT)); //for adding the button southPanel.add(exitButton); //for setting the border southPanel.setBorder(BorderFactory.createEtchedBorder()); //for add the south panel to the container cp.add("South", southPanel); removeButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { //for checking if there is a missing information Sumeet Dhende (2012450009) Jeet Dholakia (2012450010) Page 87

LIBRARY MANAGEMENT SYSTEM


if (isCorrect()) { Thread runner = new Thread() { public void run() { book = new Books(); //for getting the information book.connection("SELECT * FROM Books WHERE BookID =" + data); int bookID = book.getBookID(); int numberOfBooks = book.getNumberOfBooks(); if (bookID > 1) { if (numberOfBooks == 1) { book.update("DELETE FROM Books WHERE BookID =" + data); //for setting JTextField to null

removeTextField.setText(null); } if (numberOfBooks > 1) { numberOfBooks -= 1; book.update("UPDATE Books SET NumberOfBooks =" + numberOfBooks + " WHERE BookID =" + data); //for setting JTextField to null

removeTextField.setText(null); } } Sumeet Dhende (2012450009) Jeet Dholakia (2012450010) Page 88

LIBRARY MANAGEMENT SYSTEM


else

JOptionPane.showMessageDialog(null, "The BookID is wrong!", "Error", JOptionPane.ERROR_MESSAGE); } }; runner.start(); } //if there is a missing data, then display Message Dialog else { JOptionPane.showMessageDialog(null, "Please, complete the information", "Warning", JOptionPane.WARNING_MESSAGE); } } }); //for adding the action listener for the button to dispose the frame exitButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { dispose(); } }); //for setting the visible to true setVisible(true); //show the internal frame pack(); } Sumeet Dhende (2012450009) Jeet Dholakia (2012450010) Page 89

LIBRARY MANAGEMENT SYSTEM


} RemoveMembers.java //import the packages for using the classes in them into the program import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; //for creating the North Panel private JPanel northPanel = new JPanel(); //for creating the label private JLabel title = new JLabel("MEMBER INFORMATION"); //for creating the Center Panel private JPanel centerPanel = new JPanel(); //for creating an Internal Panel in the center panel private JPanel removePanel = new JPanel(); //for creating the label private JLabel removeLabel = new JLabel(" Write the Member ID: "); //for creating the text field private JTextField removeTextField = new JTextField(); //for creating string to store the data private String data; //for creating an Internal Panel in the center panel private JPanel removeMemberPanel = new JPanel(); //for creating the button private JButton removeButton = new JButton("Remove"); Sumeet Dhende (2012450009) Jeet Dholakia (2012450010) Page 90

LIBRARY MANAGEMENT SYSTEM


//for creating the South Panel private JPanel southPanel = new JPanel(); //for adding the button private JButton exitButton = new JButton("Exit"); //create objects from another classes for using them in the ActionListener private Members member; //for checking the information from the text field public boolean isCorrect() { if (!removeTextField.getText().equals("")) { data = removeTextField.getText(); return true; } else return false; }

//constructor of removeMembers public RemoveMembers() { //for setting the title for the internal frame super("Remove Members", false, true, false, true); //for setting the icon setFrameIcon(new ImageIcon(ClassLoader.getSystemResource("images/Delete16.gif"))); //for getting the graphical user interface components display area Container cp = getContentPane(); Sumeet Dhende (2012450009) Jeet Dholakia (2012450010)

Page 91

LIBRARY MANAGEMENT SYSTEM


//for setting the layout northPanel.setLayout(new FlowLayout(FlowLayout.CENTER)); //for setting the font title.setFont(new Font("Tahoma", Font.BOLD, 14)); //for adding the label northPanel.add(title); //for adding the panel to the container cp.add("North", northPanel); //for setting the layout centerPanel.setLayout(new BorderLayout()); //for setting the layout removePanel.setLayout(new GridLayout(1, 2, 1, 1)); //for adding the label removePanel.add(removeLabel); //for adding the text field removePanel.add(removeTextField); //for adding the internal panel to the panel centerPanel.add("Center", removePanel); //for setting the layout removeMemberPanel.setLayout(new FlowLayout(FlowLayout.RIGHT)); //for adding the button removeMemberPanel.add(removeButton); //for addint the internal panel to the center panel centerPanel.add("South", removeMemberPanel); //for setting the border Sumeet Dhende (2012450009) Jeet Dholakia (2012450010) Page 92

LIBRARY MANAGEMENT SYSTEM


centerPanel.setBorder(BorderFactory.createTitledBorder("Remove a member:")); //for adding the center panel to the container cp.add("Center", centerPanel); removeLabel.setFont(new Font("Tahoma", Font.BOLD, 11)); removeTextField.setFont(new Font("Tahoma", Font.PLAIN, 11)); exitButton.setFont(new Font("Tahoma", Font.BOLD, 11)); removeButton.setFont(new Font("Tahoma", Font.BOLD, 11)); //for setting the layout southPanel.setLayout(new FlowLayout(FlowLayout.RIGHT)); //for adding the button southPanel.add(exitButton); //for setting the border southPanel.setBorder(BorderFactory.createEtchedBorder()); //for add the south panel to the container cp.add("South", southPanel); removeButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { //for checking if there is a missing information if (isCorrect()) { Thread runner = new Thread() { public void run() { member = new Members(); member.connection("SELECT * FROM Members WHERE MemberID = " + data);

Sumeet Dhende (2012450009) Jeet Dholakia (2012450010)

Page 93

LIBRARY MANAGEMENT SYSTEM


//for checking if the user borrowed any book form the library int numberOfBooks = member.getNumberOfBooks(); if (numberOfBooks == 0) { member.update("DELETE FROM Members WHERE MemberID = " + data); //for setting the JTextField to null removeTextField.setText(null); } else

JOptionPane.showMessageDialog(null, "Book(s) borrowed by the member", "Warning", JOptionPane.WARNING_MESSAGE); } }; runner.start(); } //if there is a missing data, then display Message Dialog else { JOptionPane.showMessageDialog(null, "Please, complete the information", "Warning", JOptionPane.WARNING_MESSAGE); } } }); //for adding the action listener for the button to dispose the frame exitButton.addActionListener(new ActionListener() { Sumeet Dhende (2012450009) Jeet Dholakia (2012450010) Page 94

LIBRARY MANAGEMENT SYSTEM


public void actionPerformed(ActionEvent ae) { dispose(); } }); //for setting the visible to true setVisible(true); //show the internal frame pack(); } }

Sumeet Dhende (2012450009) Jeet Dholakia (2012450010)

Page 95

LIBRARY MANAGEMENT SYSTEM


4.5 Snapshots of UI and Reports
Login Screen:

Main Window:

Sumeet Dhende (2012450009) Jeet Dholakia (2012450010)

Page 96

LIBRARY MANAGEMENT SYSTEM


Book Information:

List of Books:

Sumeet Dhende (2012450009) Jeet Dholakia (2012450010)

Page 97

LIBRARY MANAGEMENT SYSTEM


Edit Books:

Remove Books:

Sumeet Dhende (2012450009) Jeet Dholakia (2012450010)

Page 98

LIBRARY MANAGEMENT SYSTEM


Add Members:

Members List:

Sumeet Dhende (2012450009) Jeet Dholakia (2012450010)

Page 99

LIBRARY MANAGEMENT SYSTEM


Edit Members:

Search Function:

Sumeet Dhende (2012450009) Jeet Dholakia (2012450010)

Page 100

LIBRARY MANAGEMENT SYSTEM


Borrow Books:

Book Reservation:

Sumeet Dhende (2012450009) Jeet Dholakia (2012450010)

Page 101

LIBRARY MANAGEMENT SYSTEM CHAPTER 5 FUTURE ENHANCEMENTS


Extra and user defined security needs can be employed during request and response.

Records of students and admin activities can be maintained.

Another enhancement would be to add more modules like online library, course

allocation to cover all information off the system.

Also, a release of API version is planned so the system can be integrated with other third-

party applications. It will enhance the document management within other applications

Sumeet Dhende (2012450009) Jeet Dholakia (2012450010)

Page 102

LIBRARY MANAGEMENT SYSTEM CHAPTER 6 LIMITATIONS


All the details are in the hands of admin only.

Limited to offline only.

Limited to particular college only.

Number of server machines is assumed to be more with more number of users accessing

the system. But if the user limit exceeds, it can slow down the server system and congest the network.

Sumeet Dhende (2012450009) Jeet Dholakia (2012450010)

Page 103

LIBRARY MANAGEMENT SYSTEM CHAPTER 7 CONCLUSION


Library Management System leads to a better organization structure since the information management of the all the available books is well-structured and also leads to better as well as efficient utilization of resources. Library Management System can be used by education institutes to maintain the records of availability of books in the library easily. Achieving this objective is difficult using a manual system as the information is scattered, it can be redundant and collecting relevant information may be very time-consuming. All these problems are solved using this project.

Sumeet Dhende (2012450009) Jeet Dholakia (2012450010)

Page 104

LIBRARY MANAGEMENT SYSTEM CHAPTER 8 BIBLIOGRAPHY


J2 Complete Reference.

www.google.com.

www.wikipedia.com

www.w3schools.com Head First PHP & MySQL by Lynn Beighley and Michael Morrison(OReilly)

Sumeet Dhende (2012450009) Jeet Dholakia (2012450010)

Page 105

Das könnte Ihnen auch gefallen