aboutsummaryrefslogtreecommitdiff
path: root/src/UI/NewBookPopupWindow.java
diff options
context:
space:
mode:
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();
+ }
+}