package UI.Components; import Client.Book; import UI.MainWindow; import javax.swing.*; import javax.swing.border.EmptyBorder; import javax.swing.border.MatteBorder; import java.awt.*; 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))); boolean issued = book.getIssuedBy() != 0; JLabel titleLabel = new JLabel(book.getTitle()); titleLabel.setFont(new Font(titleLabel.getFont().getName(), Font.BOLD, titleLabel.getFont().getSize() + 2)); this.add(titleLabel); JPanel issueButtonPanel = new JPanel(); issueButtonPanel.setLayout(new FlowLayout(FlowLayout.RIGHT)); if (!issued || book.getIssuedBy() == MainWindow.userId) { JButton issueButton = new JButton(issued ? "Return Book" : "Issue Book"); issueButtonPanel.add(issueButton); issueButton.addActionListener(e -> { if (issued) { book.returnBook(); } else { book.issue(); } }); } else { issueButtonPanel.add(new JLabel("Book is Unavailable")); } this.add(issueButtonPanel); JLabel authorLabel = new JLabel(book.getAuthor()); authorLabel.setForeground(Color.DARK_GRAY); this.add(authorLabel); this.setMaximumSize(new Dimension(650, 100)); this.setLayout(new GridLayout(2, 2)); } }