aboutsummaryrefslogtreecommitdiff
path: root/src/UI/NewBookPopupWindow.java
diff options
context:
space:
mode:
authorVidhu Kant Sharma <vidhukant@vidhukant.com>2024-11-16 02:16:16 +0530
committerVidhu Kant Sharma <vidhukant@vidhukant.com>2024-11-16 02:16:16 +0530
commitda6b366397aa15e2686840c1d9ffa5dae5d49d2a (patch)
treea53bc42092a564bfbf66a67b70e3aa9cb8689798 /src/UI/NewBookPopupWindow.java
First Commit
Diffstat (limited to 'src/UI/NewBookPopupWindow.java')
-rw-r--r--src/UI/NewBookPopupWindow.java58
1 files changed, 58 insertions, 0 deletions
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();
+ }
+}