package UI; import Store.Book; import UI.Components.InputBox; import javax.swing.*; import javax.swing.border.EmptyBorder; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.sql.SQLException; public class NewBookPopupWindow extends JFrame { public InputBox titleInput; public InputBox authorInput; public JButton saveButton; public NewBookPopupWindow() { this.setTitle("Add New Book"); this.setSize(350, 200); this.setLocationRelativeTo(null); this.setLayout(new FlowLayout(FlowLayout.TRAILING)); this.titleInput = new InputBox("Title:"); this.titleInput.setBorder(new EmptyBorder(0, 10, 0, 10)); this.add(this.titleInput); this.authorInput = new InputBox("Author:"); this.authorInput.setBorder(new EmptyBorder(0, 10, 0, 10)); this.add(this.authorInput); saveButton = new JButton("Save"); JPanel buttonPanel = new JPanel(); buttonPanel.setBorder(new EmptyBorder(0, 0, 0, 12)); buttonPanel.add(saveButton); this.add(buttonPanel); saveButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Book newBook = new Book(titleInput.getValue(), authorInput.getValue()); try { setVisible(false); newBook.save(); } catch (SQLException ex) { throw new RuntimeException(ex); } } }); } public void showWindow() { this.setVisible(true); this.titleInput.setValue(""); this.authorInput.setValue(""); this.repaint(); } }