import javax.swing.*; public class guiclass implements guiinterface { private booklistinterface db = null; public void go(booklistinterface booklist) { String[] commands = {"Add / Change Entry", "Remove Entry", "Sort by Author", "Sort by Title", "List by Author", "List by Borrower", "Book Info", "Exit"}; db = booklist; int choice; do { choice = JOptionPane.showOptionDialog(null, "Select a Command", "PhoneDirectory", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, commands, commands[7]); switch (choice) { case 0: doadd(); break; // ask for data, add or edit entry from lib case 1: doremove(); break; // ask for title, remove from lib case 2: doauthorsort(); break; // sort lib by author, then show the lib case 3: dotitlesort(); break; // ditto, but by title case 4: dolistbyauthor(); break; // ask for author name, show his books (no lib sorting) case 5: dolistbyborrower(); break; // ditto, but for borrower case 6: dobookinfo(); break; // ask for title, give info for that book default: } } while (choice != 7); dosave(); System.exit(0); } private void doadd() { String title, author, pagetotal, year, price, borrower, m; title = JOptionPane.showInputDialog("Enter title"); if (title == null) return; author = JOptionPane.showInputDialog("Enter author"); if (author == null) return; pagetotal = JOptionPane.showInputDialog("Enter the total number of pages"); if (pagetotal == null) return; year = JOptionPane.showInputDialog("Enter year"); if (year == null) return; price = JOptionPane.showInputDialog("Enter price"); if (price == null) return; borrower = JOptionPane.showInputDialog("Enter borrower"); if (borrower == null) return; if (db.addbook(title, author, pagetotal, year, price, borrower)) m = "The book was added: "; else m = "The book was edited: "; m += title + ", " + author + ", " + pagetotal + ", " + year + ", " + price + ", " + borrower; JOptionPane.showMessageDialog(null, m); } private void doremove() { String t = JOptionPane.showInputDialog("Enter book title"), m; if (t == null) return; if (db.removebook(t)) m = "The book was removed"; else m = "The book is MIA!"; JOptionPane.showMessageDialog(null, m); } private void doauthorsort() { JOptionPane.showMessageDialog(null, db.authorsort()); } private void dotitlesort() { JOptionPane.showMessageDialog(null, db.titlesort()); } private void dolistbyauthor() { String l = JOptionPane.showInputDialog("Enter book author"); if (l == null) return; JOptionPane.showMessageDialog(null, db.listbyauthor(l)); } private void dolistbyborrower() { String l = JOptionPane.showInputDialog("Enter book borrower"); if (l == null) return; JOptionPane.showMessageDialog(null, db.listbyborrower(l)); } private void dobookinfo () { String l = JOptionPane.showInputDialog("Enter book title"); if (l == null) return; JOptionPane.showMessageDialog(null, db.bookinfo(l)); } private void dosave() { db.savefile(); } }