diff options
author | Vidhu Kant Sharma <vidhukant@vidhukant.com> | 2024-11-16 02:16:16 +0530 |
---|---|---|
committer | Vidhu Kant Sharma <vidhukant@vidhukant.com> | 2024-11-16 02:16:16 +0530 |
commit | da6b366397aa15e2686840c1d9ffa5dae5d49d2a (patch) | |
tree | a53bc42092a564bfbf66a67b70e3aa9cb8689798 /src/UI/Components/BookListItem.java |
First Commit
Diffstat (limited to 'src/UI/Components/BookListItem.java')
-rw-r--r-- | src/UI/Components/BookListItem.java | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/src/UI/Components/BookListItem.java b/src/UI/Components/BookListItem.java new file mode 100644 index 0000000..1204f76 --- /dev/null +++ b/src/UI/Components/BookListItem.java @@ -0,0 +1,48 @@ +package UI.Components; + +import Store.Book; + +import javax.swing.*; +import javax.swing.border.EmptyBorder; +import javax.swing.border.MatteBorder; +import java.awt.*; +import java.sql.SQLException; +import java.util.Objects; + +public class BookListItem extends JPanel { + BookListItem(Book book) { + this.setBorder(BorderFactory.createCompoundBorder(new EmptyBorder(6, 10, 6, 10), new MatteBorder(0, 0, 1, 0, Color.BLACK))); + + JLabel titleLabel = new JLabel(book.getTitle()); + titleLabel.setFont(new Font(titleLabel.getFont().getName(), Font.BOLD, titleLabel.getFont().getSize() + 2)); + this.add(titleLabel); + + JPanel deleteButtonPanel = new JPanel(); + JButton deleteButton = new JButton("Delete Book"); + deleteButtonPanel.setLayout(new FlowLayout(FlowLayout.RIGHT)); + deleteButtonPanel.add(deleteButton); + this.add(deleteButtonPanel); + + deleteButton.addActionListener(e -> { + try { + book.delete(); + } catch (SQLException ex) { + throw new RuntimeException(ex); + } + }); + + JLabel authorLabel = new JLabel(book.getAuthor()); + authorLabel.setForeground(Color.DARK_GRAY); + this.add(authorLabel); + + JPanel issuedByLabelPanel = new JPanel(); + JLabel issuedByLabel = new JLabel(!Objects.equals(book.getIssuedByName(), null) ? "Issued by user " + book.getIssuedByName() : "Available"); + issuedByLabelPanel.setLayout(new FlowLayout(FlowLayout.RIGHT)); + issuedByLabelPanel.add(issuedByLabel); + this.add(issuedByLabelPanel); + + this.setMaximumSize(new Dimension(650, 100)); + this.setLayout(new GridLayout(2, 2)); + } +} + |