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/Components/BookListItem.java | 48 +++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 src/UI/Components/BookListItem.java (limited to 'src/UI/Components/BookListItem.java') 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)); + } +} + -- cgit v1.2.3