import javax.swing.*; import java.awt.*; public class BookFormPanel extends JPanel { private final LibraryController controller; public BookFormPanel(LibraryController controller) { this.controller = controller; buildUI(); } private void buildUI() { setLayout(new BorderLayout()); JLabel header = new JLabel("Book Management", SwingConstants.CENTER); header.setFont(new Font("Arial", Font.BOLD, 18)); add(header, BorderLayout.NORTH); JPanel form = new JPanel(new GridLayout(4, 2, 10, 10)); JTextField isbnField = new JTextField(); JTextField titleField = new JTextField(); JButton addBtn = new JButton("Add Book"); JButton searchBtn = new JButton("Search"); form.add(new JLabel("ISBN:")); form.add(isbnField); form.add(new JLabel("Title:")); form.add(titleField); form.add(addBtn); form.add(searchBtn); JPanel formWrapper = new JPanel(new FlowLayout(FlowLayout.LEFT)); formWrapper.add(form); add(formWrapper, BorderLayout.WEST); JTextArea output = new JTextArea(); output.setEditable(false); add(new JScrollPane(output), BorderLayout.CENTER); addBtn.addActionListener(e -> { String isbn = isbnField.getText().trim(); String title = titleField.getText().trim(); if (isbn.isEmpty() || title.isEmpty()) { JOptionPane.showMessageDialog(this, "Please fill all fields."); return; } controller.addBook(new Book(isbn, title)); output.setText("Book added:\n" + isbn + " - " + title); }); searchBtn.addActionListener(e -> { String isbn = isbnField.getText().trim(); Book b = controller.findBook(isbn); if (b == null) { output.setText("Book not found."); } else { output.setText("Book found:\nISBN: " + b.getIsbn() + "\nTitle: " + b.getTitle()); } }); } }