blob: f50f3e6df3fa05671c49e9de81adac6e31e49da0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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();
}
}
|