From b6869036b7839b4540cee1114f44bc5c9b33d9c4 Mon Sep 17 00:00:00 2001 From: Josh Walters Date: Tue, 13 Dec 2011 17:35:57 -0800 Subject: Initial commit of code. --- src/com/joshwalters/bookcatalog/DeleteBook.java | 120 ++++++++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 src/com/joshwalters/bookcatalog/DeleteBook.java (limited to 'src/com/joshwalters/bookcatalog/DeleteBook.java') diff --git a/src/com/joshwalters/bookcatalog/DeleteBook.java b/src/com/joshwalters/bookcatalog/DeleteBook.java new file mode 100644 index 0000000..7f0bffc --- /dev/null +++ b/src/com/joshwalters/bookcatalog/DeleteBook.java @@ -0,0 +1,120 @@ +/* + * 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()); + } + } +} -- cgit v1.2.3-24-g4f1b