SlideShare a Scribd company logo
1 of 8
Download to read offline
Objective:
Create a graphical database for a library IN JAVA. It should display the information of every
book in the library system. Each book should have the following information:
Name
Author(s)
Year published
Publisher
ISBN
Page Count
The system should be able to perform the following operations:
Display books in alphabetical order
Either all books or the books that met a search criteria noted below
Add a book
Remove a book
Search books based on
Name
Author
Year
Publisher
ISBN
Load a library database file
Save a library database file
Solution
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import javax.swing.JFileChooser;
import javax.swing.table.DefaultTableModel;
public class Library extends javax.swing.JFrame {
public Library() {
initComponents();
}
@SuppressWarnings("unchecked")
private void initComponents() {
jScrollPane1 = new javax.swing.JScrollPane();
table = new javax.swing.JTable();
name = new javax.swing.JTextField();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
author = new javax.swing.JTextField();
jLabel3 = new javax.swing.JLabel();
year = new javax.swing.JTextField();
jLabel4 = new javax.swing.JLabel();
publisher = new javax.swing.JTextField();
add = new javax.swing.JButton();
Delete = new javax.swing.JButton();
Edit = new javax.swing.JButton();
jLabel5 = new javax.swing.JLabel();
isbn = new javax.swing.JTextField();
Search = new javax.swing.JButton();
jLabel6 = new javax.swing.JLabel();
pageCount = new javax.swing.JTextField();
select = new javax.swing.JComboBox();
searchMessage = new javax.swing.JLabel();
jMenuBar1 = new javax.swing.JMenuBar();
jMenu1 = new javax.swing.JMenu();
load = new javax.swing.JMenuItem();
save = new javax.swing.JMenuItem();
jMenu2 = new javax.swing.JMenu();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
table.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{null, null, null, null, null, null},
{null, null, null, null, null, null},
{null, null, null, null, null, null},
{null, null, null, null, null, null}
},
new String [] {
"Name", "Author", "Year Published", "Publisher", "ISBN", "Page Count"
}
) {
Class[] types = new Class [] {
java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class,
java.lang.String.class, java.lang.Object.class
};
boolean[] canEdit = new boolean [] {
false, false, false, false, true, false
};
public Class getColumnClass(int columnIndex) {
return types [columnIndex];
}
public boolean isCellEditable(int rowIndex, int columnIndex) {
return canEdit [columnIndex];
}
});
jScrollPane1.setViewportView(table);
jLabel1.setText("Name:");
jLabel2.setText("Author:");
jLabel3.setText("Year:");
jLabel4.setText("Publisher:");
add.setText("Add");
add.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
addActionPerformed(evt);
}
});
Delete.setText("Delete");
Delete.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
DeleteActionPerformed(evt);
}
});
Edit.setText("Edit");
Edit.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
EditActionPerformed(evt);
}
});
jLabel5.setText("ISBN:");
Search.setText("Search");
Search.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
SearchActionPerformed(evt);
}
});
jLabel6.setText("Page Count:");
select.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Name", "Author",
"Year", "Publisher", "ISBN" }));
searchMessage.setText(" ");
jMenu1.setText("File");
load.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_O,
java.awt.event.InputEvent.CTRL_MASK));
load.setText("Load Database");
load.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
loadActionPerformed(evt);
}
});
jMenu1.add(load);
save.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S,
java.awt.event.InputEvent.CTRL_MASK));
save.setText("Save Database");
save.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
saveActionPerformed(evt);
}
});
jMenu1.add(save);
jMenuBar1.add(jMenu1);
jMenu2.setText("Help");
jMenuBar1.add(jMenu2);
setJMenuBar(jMenuBar1);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(28, 28, 28)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel1)
.addGap(18, 18, 18)
.addComponent(name, javax.swing.GroupLayout.PREFERRED_SIZE, 84,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jLabel2)
.addGap(18, 18, 18)
.addComponent(author, javax.swing.GroupLayout.PREFERRED_SIZE, 84,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(jLabel3)
.addGap(18, 18, 18)
.addComponent(year, javax.swing.GroupLayout.PREFERRED_SIZE, 84,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(jLabel4)
.addGap(18, 18, 18)
.addComponent(publisher, javax.swing.GroupLayout.PREFERRED_SIZE, 84,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(jLabel5)
.addGap(18, 18, 18)
.addComponent(isbn, javax.swing.GroupLayout.PREFERRED_SIZE, 84,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addGap(212, 212, 212)
.addComponent(add)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(Delete)
.addGap(18, 18, 18)
.addComponent(Edit)
.addGap(18, 18, 18)
.addComponent(select, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(Search)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 30,
Short.MAX_VALUE)
.addComponent(jLabel6)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(pageCount, javax.swing.GroupLayout.PREFERRED_SIZE, 84,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18))
.addGroup(layout.createSequentialGroup()
.addGap(20, 20, 20)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(searchMessage, javax.swing.GroupLayout.Alignment.TRAILING,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE)
.addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING,
javax.swing.GroupLayout.DEFAULT_SIZE, 914, Short.MAX_VALUE))
.addContainerGap(32, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGap(27, 27, 27)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 113,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(27, 27, 27)
.addComponent(searchMessage)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(name, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel1)
.addComponent(author, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel2)
.addComponent(year, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel3)
.addComponent(publisher, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel4)
.addComponent(isbn, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel5)
.addComponent(pageCount, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel6))
.addGap(35, 35, 35)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(Delete)
.addComponent(Edit)
.addComponent(select, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(Search)
.addComponent(add))
.addGap(25, 25, 25))
);
pack();
}
private void addActionPerformed(java.awt.event.ActionEvent evt) {
if(table.getRowCount() == i)
{
DefaultTableModel dtm = (DefaultTableModel) table.getModel();
dtm.addRow(new Object[]{"","","","","",""});
}
table.setValueAt(name.getText(), i, 0 );
table.setValueAt(author.getText(), i, 1 );
table.setValueAt(year.getText(), i, 2 );
table.setValueAt(publisher.getText(), i, 3 );
table.setValueAt(isbn.getText(), i, 4 );
table.setValueAt(pageCount.getText(), i, 5 );
i++;
}
private void DeleteActionPerformed(java.awt.event.ActionEvent evt) {
for(int j=0;j

More Related Content

Similar to ObjectiveCreate a graphical database for a library IN JAVA. It sh.pdf

BookStoreCXFWS.classpathBookStoreCXFWS.project CXF.docx
BookStoreCXFWS.classpathBookStoreCXFWS.project  CXF.docxBookStoreCXFWS.classpathBookStoreCXFWS.project  CXF.docx
BookStoreCXFWS.classpathBookStoreCXFWS.project CXF.docx
hartrobert670
 
import javaawt import javaxswing import javaxswing.pdf
import javaawt import javaxswing import javaxswing.pdfimport javaawt import javaxswing import javaxswing.pdf
import javaawt import javaxswing import javaxswing.pdf
ADITIEYEWEAR
 
Java căn bản - Chapter2
Java căn bản - Chapter2Java căn bản - Chapter2
Java căn bản - Chapter2
Vince Vo
 
In Java Write a GUI application to simulate writing out a check. The.pdf
In Java Write a GUI application to simulate writing out a check. The.pdfIn Java Write a GUI application to simulate writing out a check. The.pdf
In Java Write a GUI application to simulate writing out a check. The.pdf
flashfashioncasualwe
 
correct the error import javaxswingJFrame import javaxs.pdf
correct the error import javaxswingJFrame import javaxs.pdfcorrect the error import javaxswingJFrame import javaxs.pdf
correct the error import javaxswingJFrame import javaxs.pdf
devangmittal4
 

Similar to ObjectiveCreate a graphical database for a library IN JAVA. It sh.pdf (20)

A Scala tutorial
A Scala tutorialA Scala tutorial
A Scala tutorial
 
Java session4
Java session4Java session4
Java session4
 
Java
JavaJava
Java
 
BookStoreCXFWS.classpathBookStoreCXFWS.project CXF.docx
BookStoreCXFWS.classpathBookStoreCXFWS.project  CXF.docxBookStoreCXFWS.classpathBookStoreCXFWS.project  CXF.docx
BookStoreCXFWS.classpathBookStoreCXFWS.project CXF.docx
 
Bean Intro
Bean IntroBean Intro
Bean Intro
 
The Django Book chapter 5 Models
The Django Book chapter 5 ModelsThe Django Book chapter 5 Models
The Django Book chapter 5 Models
 
CS2309 JAVA LAB MANUAL
CS2309 JAVA LAB MANUALCS2309 JAVA LAB MANUAL
CS2309 JAVA LAB MANUAL
 
DSJ_Unit III.pdf
DSJ_Unit III.pdfDSJ_Unit III.pdf
DSJ_Unit III.pdf
 
Java swing
Java swingJava swing
Java swing
 
import javaawt import javaxswing import javaxswing.pdf
import javaawt import javaxswing import javaxswing.pdfimport javaawt import javaxswing import javaxswing.pdf
import javaawt import javaxswing import javaxswing.pdf
 
Jface
JfaceJface
Jface
 
Scala ntnu
Scala ntnuScala ntnu
Scala ntnu
 
JUG Berlin Brandenburg: What's new in Java EE 7?
JUG Berlin Brandenburg: What's new in Java EE 7?JUG Berlin Brandenburg: What's new in Java EE 7?
JUG Berlin Brandenburg: What's new in Java EE 7?
 
Presentation to java
Presentation  to  javaPresentation  to  java
Presentation to java
 
Chapter 2 - Getting Started with Java
Chapter 2 - Getting Started with JavaChapter 2 - Getting Started with Java
Chapter 2 - Getting Started with Java
 
Java căn bản - Chapter2
Java căn bản - Chapter2Java căn bản - Chapter2
Java căn bản - Chapter2
 
In Java Write a GUI application to simulate writing out a check. The.pdf
In Java Write a GUI application to simulate writing out a check. The.pdfIn Java Write a GUI application to simulate writing out a check. The.pdf
In Java Write a GUI application to simulate writing out a check. The.pdf
 
correct the error import javaxswingJFrame import javaxs.pdf
correct the error import javaxswingJFrame import javaxs.pdfcorrect the error import javaxswingJFrame import javaxs.pdf
correct the error import javaxswingJFrame import javaxs.pdf
 
Write a GUI application to simulate writing out a check. The value o.pdf
Write a GUI application to simulate writing out a check. The value o.pdfWrite a GUI application to simulate writing out a check. The value o.pdf
Write a GUI application to simulate writing out a check. The value o.pdf
 
College management system.pptx
College management system.pptxCollege management system.pptx
College management system.pptx
 

More from ezzi97

Explain why multiple processes cannot share data easilySolution.pdf
Explain why multiple processes cannot share data easilySolution.pdfExplain why multiple processes cannot share data easilySolution.pdf
Explain why multiple processes cannot share data easilySolution.pdf
ezzi97
 
create a narrative budget blueprint for a local unit of government. .pdf
create a narrative budget blueprint for a local unit of government. .pdfcreate a narrative budget blueprint for a local unit of government. .pdf
create a narrative budget blueprint for a local unit of government. .pdf
ezzi97
 
C++You will design a program to play a simplified version of war, .pdf
C++You will design a program to play a simplified version of war, .pdfC++You will design a program to play a simplified version of war, .pdf
C++You will design a program to play a simplified version of war, .pdf
ezzi97
 
1. Which of the following statements would correctly print out t.pdf
1. Which of the following statements would correctly print out t.pdf1. Which of the following statements would correctly print out t.pdf
1. Which of the following statements would correctly print out t.pdf
ezzi97
 
2.How important is it to involve physicians in financial improvement.pdf
2.How important is it to involve physicians in financial improvement.pdf2.How important is it to involve physicians in financial improvement.pdf
2.How important is it to involve physicians in financial improvement.pdf
ezzi97
 
Write one page essay to explain how you relate signals and systems t.pdf
Write one page essay to explain how you relate signals and systems t.pdfWrite one page essay to explain how you relate signals and systems t.pdf
Write one page essay to explain how you relate signals and systems t.pdf
ezzi97
 
Write 2 to 3 paragraphs aboutONE DDoS attack that occurred in 2016.pdf
Write 2 to 3 paragraphs aboutONE DDoS attack that occurred in 2016.pdfWrite 2 to 3 paragraphs aboutONE DDoS attack that occurred in 2016.pdf
Write 2 to 3 paragraphs aboutONE DDoS attack that occurred in 2016.pdf
ezzi97
 
Who are stakeholders Define who they are and then please share what.pdf
Who are stakeholders Define who they are and then please share what.pdfWho are stakeholders Define who they are and then please share what.pdf
Who are stakeholders Define who they are and then please share what.pdf
ezzi97
 
Link to assignment that I need help with is below httpweb.cse..pdf
Link to assignment that I need help with is below httpweb.cse..pdfLink to assignment that I need help with is below httpweb.cse..pdf
Link to assignment that I need help with is below httpweb.cse..pdf
ezzi97
 

More from ezzi97 (20)

Explain why multiple processes cannot share data easilySolution.pdf
Explain why multiple processes cannot share data easilySolution.pdfExplain why multiple processes cannot share data easilySolution.pdf
Explain why multiple processes cannot share data easilySolution.pdf
 
executive summary for law enforcement using dronesSolutionUse .pdf
executive summary for law enforcement using dronesSolutionUse .pdfexecutive summary for law enforcement using dronesSolutionUse .pdf
executive summary for law enforcement using dronesSolutionUse .pdf
 
Discuss how your life and experience with social mediaweb 2.0 compa.pdf
Discuss how your life and experience with social mediaweb 2.0 compa.pdfDiscuss how your life and experience with social mediaweb 2.0 compa.pdf
Discuss how your life and experience with social mediaweb 2.0 compa.pdf
 
create a narrative budget blueprint for a local unit of government. .pdf
create a narrative budget blueprint for a local unit of government. .pdfcreate a narrative budget blueprint for a local unit of government. .pdf
create a narrative budget blueprint for a local unit of government. .pdf
 
define three types of kernal-mode to user mode transfersSolution.pdf
define three types of kernal-mode to user mode transfersSolution.pdfdefine three types of kernal-mode to user mode transfersSolution.pdf
define three types of kernal-mode to user mode transfersSolution.pdf
 
Arrange the steps of DNA replication in the order that they occur. D.pdf
Arrange the steps of DNA replication in the order that they occur.  D.pdfArrange the steps of DNA replication in the order that they occur.  D.pdf
Arrange the steps of DNA replication in the order that they occur. D.pdf
 
C++You will design a program to play a simplified version of war, .pdf
C++You will design a program to play a simplified version of war, .pdfC++You will design a program to play a simplified version of war, .pdf
C++You will design a program to play a simplified version of war, .pdf
 
(c) After conducting several measurements, the Beijing Municipal Env.pdf
(c) After conducting several measurements, the Beijing Municipal Env.pdf(c) After conducting several measurements, the Beijing Municipal Env.pdf
(c) After conducting several measurements, the Beijing Municipal Env.pdf
 
1. Which of the following statements would correctly print out t.pdf
1. Which of the following statements would correctly print out t.pdf1. Which of the following statements would correctly print out t.pdf
1. Which of the following statements would correctly print out t.pdf
 
2.How important is it to involve physicians in financial improvement.pdf
2.How important is it to involve physicians in financial improvement.pdf2.How important is it to involve physicians in financial improvement.pdf
2.How important is it to involve physicians in financial improvement.pdf
 
Write one page essay to explain how you relate signals and systems t.pdf
Write one page essay to explain how you relate signals and systems t.pdfWrite one page essay to explain how you relate signals and systems t.pdf
Write one page essay to explain how you relate signals and systems t.pdf
 
Why do IDPs & IDRs lack structure Lack a ligand or partner Denatu.pdf
Why do IDPs & IDRs lack structure  Lack a ligand or partner  Denatu.pdfWhy do IDPs & IDRs lack structure  Lack a ligand or partner  Denatu.pdf
Why do IDPs & IDRs lack structure Lack a ligand or partner Denatu.pdf
 
Write 2 to 3 paragraphs aboutONE DDoS attack that occurred in 2016.pdf
Write 2 to 3 paragraphs aboutONE DDoS attack that occurred in 2016.pdfWrite 2 to 3 paragraphs aboutONE DDoS attack that occurred in 2016.pdf
Write 2 to 3 paragraphs aboutONE DDoS attack that occurred in 2016.pdf
 
Why is methyl salicylate not appreciably soluble in waterSoluti.pdf
Why is methyl salicylate not appreciably soluble in waterSoluti.pdfWhy is methyl salicylate not appreciably soluble in waterSoluti.pdf
Why is methyl salicylate not appreciably soluble in waterSoluti.pdf
 
Who are stakeholders Define who they are and then please share what.pdf
Who are stakeholders Define who they are and then please share what.pdfWho are stakeholders Define who they are and then please share what.pdf
Who are stakeholders Define who they are and then please share what.pdf
 
What was the biggest problem with the Articles of Confederation They.pdf
What was the biggest problem with the Articles of Confederation They.pdfWhat was the biggest problem with the Articles of Confederation They.pdf
What was the biggest problem with the Articles of Confederation They.pdf
 
What is UWIN and what does it doSolutionUWin is a software .pdf
What is UWIN and what does it doSolutionUWin is a software .pdfWhat is UWIN and what does it doSolutionUWin is a software .pdf
What is UWIN and what does it doSolutionUWin is a software .pdf
 
What sort of archaeological remains have been discovered on the site.pdf
What sort of archaeological remains have been discovered on the site.pdfWhat sort of archaeological remains have been discovered on the site.pdf
What sort of archaeological remains have been discovered on the site.pdf
 
Link to assignment that I need help with is below httpweb.cse..pdf
Link to assignment that I need help with is below httpweb.cse..pdfLink to assignment that I need help with is below httpweb.cse..pdf
Link to assignment that I need help with is below httpweb.cse..pdf
 
The Food Stamp Program is Americas first line of defense against hu.pdf
The Food Stamp Program is Americas first line of defense against hu.pdfThe Food Stamp Program is Americas first line of defense against hu.pdf
The Food Stamp Program is Americas first line of defense against hu.pdf
 

Recently uploaded

Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
EADTU
 

Recently uploaded (20)

PSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxPSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptx
 
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
 
Mattingly "AI & Prompt Design: Named Entity Recognition"
Mattingly "AI & Prompt Design: Named Entity Recognition"Mattingly "AI & Prompt Design: Named Entity Recognition"
Mattingly "AI & Prompt Design: Named Entity Recognition"
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & Systems
 
An overview of the various scriptures in Hinduism
An overview of the various scriptures in HinduismAn overview of the various scriptures in Hinduism
An overview of the various scriptures in Hinduism
 
Including Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdfIncluding Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdf
 
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of TransportBasic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
 
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community PartnershipsSpring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
 
How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17
 
Mattingly "AI and Prompt Design: LLMs with NER"
Mattingly "AI and Prompt Design: LLMs with NER"Mattingly "AI and Prompt Design: LLMs with NER"
Mattingly "AI and Prompt Design: LLMs with NER"
 
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
 
Observing-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxObserving-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptx
 
How to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptxHow to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptx
 
Improved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio AppImproved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio App
 
ESSENTIAL of (CS/IT/IS) class 07 (Networks)
ESSENTIAL of (CS/IT/IS) class 07 (Networks)ESSENTIAL of (CS/IT/IS) class 07 (Networks)
ESSENTIAL of (CS/IT/IS) class 07 (Networks)
 
male presentation...pdf.................
male presentation...pdf.................male presentation...pdf.................
male presentation...pdf.................
 
diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....
 
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjStl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
 
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUMDEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
 
Supporting Newcomer Multilingual Learners
Supporting Newcomer  Multilingual LearnersSupporting Newcomer  Multilingual Learners
Supporting Newcomer Multilingual Learners
 

ObjectiveCreate a graphical database for a library IN JAVA. It sh.pdf

  • 1. Objective: Create a graphical database for a library IN JAVA. It should display the information of every book in the library system. Each book should have the following information: Name Author(s) Year published Publisher ISBN Page Count The system should be able to perform the following operations: Display books in alphabetical order Either all books or the books that met a search criteria noted below Add a book Remove a book Search books based on Name Author Year Publisher ISBN Load a library database file Save a library database file Solution import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileWriter; import java.io.IOException; import java.io.InputStreamReader; import javax.swing.JFileChooser; import javax.swing.table.DefaultTableModel; public class Library extends javax.swing.JFrame {
  • 2. public Library() { initComponents(); } @SuppressWarnings("unchecked") private void initComponents() { jScrollPane1 = new javax.swing.JScrollPane(); table = new javax.swing.JTable(); name = new javax.swing.JTextField(); jLabel1 = new javax.swing.JLabel(); jLabel2 = new javax.swing.JLabel(); author = new javax.swing.JTextField(); jLabel3 = new javax.swing.JLabel(); year = new javax.swing.JTextField(); jLabel4 = new javax.swing.JLabel(); publisher = new javax.swing.JTextField(); add = new javax.swing.JButton(); Delete = new javax.swing.JButton(); Edit = new javax.swing.JButton(); jLabel5 = new javax.swing.JLabel(); isbn = new javax.swing.JTextField(); Search = new javax.swing.JButton(); jLabel6 = new javax.swing.JLabel(); pageCount = new javax.swing.JTextField(); select = new javax.swing.JComboBox(); searchMessage = new javax.swing.JLabel(); jMenuBar1 = new javax.swing.JMenuBar(); jMenu1 = new javax.swing.JMenu(); load = new javax.swing.JMenuItem(); save = new javax.swing.JMenuItem(); jMenu2 = new javax.swing.JMenu(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); table.setModel(new javax.swing.table.DefaultTableModel( new Object [][] { {null, null, null, null, null, null}, {null, null, null, null, null, null},
  • 3. {null, null, null, null, null, null}, {null, null, null, null, null, null} }, new String [] { "Name", "Author", "Year Published", "Publisher", "ISBN", "Page Count" } ) { Class[] types = new Class [] { java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.Object.class }; boolean[] canEdit = new boolean [] { false, false, false, false, true, false }; public Class getColumnClass(int columnIndex) { return types [columnIndex]; } public boolean isCellEditable(int rowIndex, int columnIndex) { return canEdit [columnIndex]; } }); jScrollPane1.setViewportView(table); jLabel1.setText("Name:"); jLabel2.setText("Author:"); jLabel3.setText("Year:"); jLabel4.setText("Publisher:"); add.setText("Add"); add.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { addActionPerformed(evt); } }); Delete.setText("Delete"); Delete.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { DeleteActionPerformed(evt);
  • 4. } }); Edit.setText("Edit"); Edit.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { EditActionPerformed(evt); } }); jLabel5.setText("ISBN:"); Search.setText("Search"); Search.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { SearchActionPerformed(evt); } }); jLabel6.setText("Page Count:"); select.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Name", "Author", "Year", "Publisher", "ISBN" })); searchMessage.setText(" "); jMenu1.setText("File"); load.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_O, java.awt.event.InputEvent.CTRL_MASK)); load.setText("Load Database"); load.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { loadActionPerformed(evt); } }); jMenu1.add(load); save.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.CTRL_MASK)); save.setText("Save Database"); save.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { saveActionPerformed(evt); }
  • 5. }); jMenu1.add(save); jMenuBar1.add(jMenu1); jMenu2.setText("Help"); jMenuBar1.add(jMenu2); setJMenuBar(jMenuBar1); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(28, 28, 28) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addComponent(jLabel1) .addGap(18, 18, 18) .addComponent(name, javax.swing.GroupLayout.PREFERRED_SIZE, 84, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(jLabel2) .addGap(18, 18, 18) .addComponent(author, javax.swing.GroupLayout.PREFERRED_SIZE, 84, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18) .addComponent(jLabel3) .addGap(18, 18, 18) .addComponent(year, javax.swing.GroupLayout.PREFERRED_SIZE, 84, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18) .addComponent(jLabel4) .addGap(18, 18, 18) .addComponent(publisher, javax.swing.GroupLayout.PREFERRED_SIZE, 84, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18) .addComponent(jLabel5) .addGap(18, 18, 18)
  • 6. .addComponent(isbn, javax.swing.GroupLayout.PREFERRED_SIZE, 84, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(layout.createSequentialGroup() .addGap(212, 212, 212) .addComponent(add) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(Delete) .addGap(18, 18, 18) .addComponent(Edit) .addGap(18, 18, 18) .addComponent(select, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18) .addComponent(Search))) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 30, Short.MAX_VALUE) .addComponent(jLabel6) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(pageCount, javax.swing.GroupLayout.PREFERRED_SIZE, 84, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18)) .addGroup(layout.createSequentialGroup() .addGap(20, 20, 20) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(searchMessage, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 914, Short.MAX_VALUE)) .addContainerGap(32, Short.MAX_VALUE)) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addGap(27, 27, 27) .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 113,
  • 7. javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(27, 27, 27) .addComponent(searchMessage) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(name, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel1) .addComponent(author, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel2) .addComponent(year, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel3) .addComponent(publisher, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel4) .addComponent(isbn, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel5) .addComponent(pageCount, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel6)) .addGap(35, 35, 35) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(Delete) .addComponent(Edit) .addComponent(select, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(Search) .addComponent(add)) .addGap(25, 25, 25)) ); pack(); } private void addActionPerformed(java.awt.event.ActionEvent evt) {
  • 8. if(table.getRowCount() == i) { DefaultTableModel dtm = (DefaultTableModel) table.getModel(); dtm.addRow(new Object[]{"","","","","",""}); } table.setValueAt(name.getText(), i, 0 ); table.setValueAt(author.getText(), i, 1 ); table.setValueAt(year.getText(), i, 2 ); table.setValueAt(publisher.getText(), i, 3 ); table.setValueAt(isbn.getText(), i, 4 ); table.setValueAt(pageCount.getText(), i, 5 ); i++; } private void DeleteActionPerformed(java.awt.event.ActionEvent evt) { for(int j=0;j