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() {
p.
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},