From da6b366397aa15e2686840c1d9ffa5dae5d49d2a Mon Sep 17 00:00:00 2001 From: Vidhu Kant Sharma Date: Sat, 16 Nov 2024 02:16:16 +0530 Subject: First Commit --- src/UI/NewBookPopupWindow.java | 58 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 src/UI/NewBookPopupWindow.java (limited to 'src/UI/NewBookPopupWindow.java') diff --git a/src/UI/NewBookPopupWindow.java b/src/UI/NewBookPopupWindow.java new file mode 100644 index 0000000..f50f3e6 --- /dev/null +++ b/src/UI/NewBookPopupWindow.java @@ -0,0 +1,58 @@ +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(); + } +} -- cgit v1.2.3