/* * Book Catalog - Catalog your book collection. * * Copyright (C) 2009 Joshua Walters * URL: http://joshwalters.com * * This file is part of Book Catalog. * * Book Catalog is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Book Catalog is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Book Catalog. If not, see . */ package com.joshwalters.bookcatalog; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.sql.SQLException; import javax.swing.JOptionPane; import javax.swing.JTextArea; import javax.swing.JTextField; import com.joshwalters.bookcatalog.bookdatabase.BookDatabase; /** * Deletes a book from the database. * * @author Josh Walters */ public class DeleteBook implements ActionListener { private BookDatabase bookDatabase; private JTextField titleField; private JTextField authorField; private JTextField dateField; private JTextArea descriptionArea; private JTextField ISBNField; private JTextField priceField; private JTextField publisherField; private JTextField subjectField; private JTextArea notesArea; private SearchDatabase searchDatabase; /** * Get the different objects needed for the class to function. * * @param bookDatabase * @param titleField * @param authorField * @param dateField * @param descriptionArea * @param ISBNField * @param priceField * @param publisherField * @param subjectField * @param notesArea * @param searchDatabase */ public DeleteBook(BookDatabase bookDatabase, JTextField titleField, JTextField authorField, JTextField dateField, JTextArea descriptionArea, JTextField ISBNField, JTextField priceField, JTextField publisherField, JTextField subjectField, JTextArea notesArea, SearchDatabase searchDatabase) { this.bookDatabase = bookDatabase; this.titleField = titleField; this.authorField = authorField; this.dateField = dateField; this.descriptionArea = descriptionArea; this.ISBNField = ISBNField; this.priceField = priceField; this.publisherField = publisherField; this.subjectField = subjectField; this.notesArea = notesArea; this.searchDatabase = searchDatabase; } /** * The user clicked on the "Delete Book" button. Remove the book from the * database. */ public void actionPerformed(ActionEvent arg) { try { // Check if the user really wants to delete the book. int result = JOptionPane.showConfirmDialog(null, "Do you really want to delete \"" + titleField.getText() + "\" from your catalog?", "Warning", JOptionPane.YES_NO_OPTION); if (result == JOptionPane.YES_OPTION) { // Delete the book using its ISBN number. bookDatabase.deleteBook(ISBNField.getText()); // Update the table. searchDatabase.updateTableWithSearchString(); // Clear all the text fields/areas. titleField.setText(""); authorField.setText(""); dateField.setText(""); descriptionArea.setText(""); ISBNField.setText(""); priceField.setText(""); publisherField.setText(""); subjectField.setText(""); notesArea.setText(""); } } catch (SQLException e) { // There was an SQL exception. System.err.println(e.getLocalizedMessage()); } } }