HI ! could you please help me here? i'm having a problem on marking the books in my library program if it is borrowed or returned? here's where im at,
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.awt.Color;
public class Library
{
ArrayList<String> bookName = new ArrayList<String>();
{{
bookName.add("Hunger Games");
bookName.add("Catching Fire");
bookName.add("Mocking Jay");
bookName.add("The Da Vinci Code");
bookName.add("Harry Potter and The Sorcerer's Stone");
bookName.add("Harry Potter and The Chamber of Secrets");
bookName.add("Harry Potter and The Prisoner of Azkaban");
bookName.add("Harry Potter and The Goblet of Fire");
bookName.add("Harry Potter and The Order of The Phoenix");
bookName.add("Harry Potter and The Half-blood Prince");
bookName.add("Harry Potter and The Deathly Hallows");
}}
ArrayList<String> bookAuthor = new ArrayList<String>();
{{
bookAuthor.add("Suzanne Collins");
bookAuthor.add("Suzanne Collins");
bookAuthor.add("Suzanne Collins");
bookAuthor.add("Dan Brown");
bookAuthor.add("J.K. Rowling");
bookAuthor.add("J.K. Rowling");
bookAuthor.add("J.K. Rowling");
bookAuthor.add("J.K. Rowling");
bookAuthor.add("J.K. Rowling");
bookAuthor.add("J.K. Rowling");
bookAuthor.add("J.K. Rowling");
}}
ArrayList<String> bookPublisher = new ArrayList<String>();
{{
bookPublisher.add("Scholastic Press");
bookPublisher.add("Scholastic Press");
bookPublisher.add("Scholastic Press");
bookPublisher.add("Doubleday Group");
bookPublisher.add("Arthur A. Levine Books");
bookPublisher.add("Arthur A. Levine Books");
bookPublisher.add("Arthur A. Levine Books");
bookPublisher.add("Arthur A. Levine Books");
bookPublisher.add("Arthur A. Levine Books");
bookPublisher.add("Arthur A. Levine Books");
bookPublisher.add("Arthur A. Levine Books");
}}
ArrayList<Integer> bookID = new ArrayList<Integer>();
{{
bookID.add(1001);
bookID.add(1002);
bookID.add(1003);
bookID.add(1004);
bookID.add(1005);
bookID.add(1006);
bookID.add(1007);
bookID.add(1008);
bookID.add(1009);
bookID.add(1010);
bookID.add(1011);
}}
boolean borrowed;
JFrame myFrame = new JFrame("Library");
JLabel jLabel1 = new JLabel("***JhayJheDiegz Books***");
JLabel jLabel2 = new JLabel("2nd Floor S-205, Science Centrum Building,");
JLabel jLabel3 = new JLabel("Colegio de Dagupan, Arellano St. Dagupan City");
JButton jButton1 = new JButton("Search");
JButton jButton2 = new JButton("Rent");
JButton jButton3 = new JButton("Return");
JButton jButton4 = new JButton("About");
JButton jButton5 = new JButton("Add Book To Our Library");
FlowLayout layout = new FlowLayout(FlowLayout.CENTER);
Font font = new Font("Serif", Font.BOLD, 20);
private int pressed;
public Library()
{
myFrame.setBounds(485,425, 305,200);
myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
myFrame.setVisible(true);
myFrame.setLayout(layout);
myFrame.setResizable(false);
JPanel jPanel = new JPanel();
jButton1.addActionListener(new searchButton());
jButton2.addActionListener(new rentButton());
jButton3.addActionListener(new returnButton());
jButton4.addActionListener(new aboutButton());
jButton5.addActionListener(new addButton());
jButton1.setToolTipText("Search Book");
jButton2.setToolTipText("Rent Book");
jButton3.setToolTipText("Return Book");
jButton4.setToolTipText("About Our Program");
jButton5.setToolTipText("Add Book");
myFrame.add(jLabel1);
myFrame.add(jLabel2);
myFrame.add(jLabel3);
myFrame.add(jButton1);
myFrame.add(jButton2);
myFrame.add(jButton3);
myFrame.add(jButton4);
myFrame.add(jButton5);
jLabel1.setFont(font);
myFrame.getContentPane().setBackground(Color.LIGHT_GRAY);
}
public void searchBook()
{
String input;
int x;
boolean found = false;
input = JOptionPane.showInputDialog(null, "Enter Name: ");
try
{
for(x=0;x<bookName.size();x++)
{
if(input.equalsIgnoreCase(bookName.get(x)))
{
JOptionPane.showMessageDialog(null, "Book Found !" + "\nTitle: " + bookName.get(x) + "\nAuthor: " + bookAuthor.get(x) +
"\nPublisher: " + bookPublisher.get(x) + "\nISBN: " + bookID.get(x), "Book Search", JOptionPane.INFORMATION_MESSAGE);
found = true;
}
}
if(!found)
{
JOptionPane.showMessageDialog(null, "BOOK NOT FOUND !" , "Book Search", JOptionPane.ERROR_MESSAGE);
searchBook();
}
}
catch(Exception e)
{
}
}
public void rentBook()
{
//this is where i want to put my rent book statements
}
public void returnBook()
{
//this is where i want to put my return book statements
}
public void aboutBook()
{
try
{
JOptionPane.showMessageDialog(null, "Authors: " + "\nJeli Quides" + "\nEmmanuel Bulawan" + "\nJaymark Dacpano" +
"\n" + "\nWe made this program for our final requirement in our Java Programming 2, " +
"\nThis code is written in JCreator Pro from scratch, " +
"\nIf you have any questions please approach the authors mentioned above. " + "\nThank You!");
}
catch(Exception e)
{
}
}
public void addBook()
{
try
{
String bN;
String bA;
String bP;
int bI;
bN = JOptionPane.showInputDialog(null, "Enter Book Title: ", "Add Book", JOptionPane.QUESTION_MESSAGE);
bookName.add(bN);
bA = JOptionPane.showInputDialog(null, "Enter Book Author: ", "Add Book", JOptionPane.QUESTION_MESSAGE);
bookAuthor.add(bA);
bP = JOptionPane.showInputDialog(null, "Enter Book Publisher: ", "Add Book", JOptionPane.QUESTION_MESSAGE);
bookPublisher.add(bP);
String a =JOptionPane.showInputDialog(null, "Enter Book ID: ", "Add Book", JOptionPane.QUESTION_MESSAGE);
bI = Integer.parseInt(a);
bookID.add(bI);
JOptionPane.showMessageDialog(null, "Book Added ! Thank You ! ");
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null, "Please Eneter Valid ISBN !" , "Invalid Book ISBN", JOptionPane.ERROR_MESSAGE);
addBook();
}
}
class searchButton implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
searchBook();
}
}
class rentButton implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
rentBook();
}
}
class returnButton implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
returnBook();
}
}
class aboutButton implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
aboutBook();
}
}
class addButton implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
addBook();
}
}
}
class MainSystem
{
public static void main(String[] args)
{
new Library();
}
}