5025231061_EASPBO
Nama : Nadin Nabil Hafizh Ayyasy
NRP : 5025231061
EAS PBO : Implementasi Perpustakaan
1. nheritance dalam Java adalah konsep di mana sebuah class dapat mewarisi properti dan metode dari class lain. Dengan inheritance, kode dapat digunakan kembali, mempermudah pengorganisasian, dan memperkuat hierarki objek. Dengan pewarisan ini, akan menciptakan hierarki class yang terstruktur. Implementasi inhertance di FP kami adalah menggunakan library JFrame untuk menampilkan tampilkan pada java
Extends JFrame
BookDetailsPage adalah kelas yang mewarisi JFrame.
JFrame adalah sebuah kelas dalam pustaka di Java Swing. Class ini digunakan untuk membuat antarmuka pengguna berbasis jendela yang dapat menampilkan komponen grafis seperti tombol, label, dan lainnya berbasis GUI.
Dengan mewarisi JFrame, kelas BookDetailsPage dapat memiliki seluruh fungsionalitas yang disediakan oleh JFrame, seperti pengaturan ukuran jendela, close jendela, pengaturan layout, dan menambah komponen UI.
2. Fitur yang ada di FP kami :
- Searching Data
Pengguna dapat mencari buku yang ingin dibacasearchButton.addActionListener(e -> {String query = searchField.getText().toLowerCase();gridPanel.removeAll();for (Book book : books) {if (book.getTitle().toLowerCase().contains(query) || book.getAuthor().toLowerCase().contains(query)) {gridPanel.add(createBookPanel(book));}}gridPanel.revalidate();gridPanel.repaint();});
- Sorting Genre
Pengguna dapat mfilter buku bedasarkan genre yang disukaiprivate JPanel createGenrePanel() {JPanel genrePanel = new JPanel(new BorderLayout());JPanel genreOptionsPanel = new JPanel(new GridLayout(0, 5, 10, 10));String[] genres = {"Action","Adventure","Comedy","Demons","Drama","Ecchi","Fantasy","Game","Harem","Historical","Horror","Josei","Magic","Martial Arts","Mecha","Military","Music","Mystery","Psychological","Parody","Police","Romance","Samurai","School","Sci-Fi","Seinen","Shoujo","Shoujo Ai","Shounen","Slice of Life","Sports","Space","Super Power","Supernatural","Thriller","Vampire"};JPanel genreBooksPanel = new JPanel(new GridLayout(0, 4, 10, 10));for (String genre : genres) {JLabel genreLabel = new JLabel(genre);genreLabel.setForeground(Color.BLUE);genreLabel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));genreLabel.addMouseListener(new MouseAdapter() {@Overridepublic void mouseClicked(MouseEvent e) {genreBooksPanel.removeAll();for (Book book : books) {if (book.getGenres().contains(genre)) {genreBooksPanel.add(createBookPanel(book));}}genreBooksPanel.revalidate();genreBooksPanel.repaint();}});genreOptionsPanel.add(genreLabel);}genrePanel.add(genreOptionsPanel, BorderLayout.NORTH);genrePanel.add(new JScrollPane(genreBooksPanel), BorderLayout.CENTER);return genrePanel;}
- Create, Read, Update, dan Delete
Pengguna dapat menambahkan mengedit dan menghapus daftar bukuclass AddBookListener implements ActionListener {public void actionPerformed(ActionEvent e) {JTextField titleField = new JTextField();JTextField authorField = new JTextField();JTextField yearField = new JTextField();JTextField genreField = new JTextField();JTextField imagePathField = new JTextField();JTextArea description = new JTextArea(5, 20);description.setLineWrap(true); // Agar teks terbungkus jika panjangdescription.setWrapStyleWord(true); // Agar teks terbungkus di kata, bukan di tengahJScrollPane descriptionScroll = new JScrollPane(description);Object[] inputFields = {"Title:", titleField, "Author:", authorField, "Year:", yearField,"Genres (comma-separated):", genreField, "Image Path:", imagePathField, "Descripton:", description};if (JOptionPane.showConfirmDialog(frame, inputFields, "Add Book", JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION) {List<String> genres = Arrays.asList(genreField.getText().split(","));books.add(new Book(titleField.getText(), authorField.getText(), yearField.getText(), genres, imagePathField.getText(), description.getText()));updateGridPanel();}}}class EditBookListener implements ActionListener {public void actionPerformed(ActionEvent e) {String title = JOptionPane.showInputDialog(frame, "Enter the title of the book to edit:");if (title == null || title.isEmpty()) return;for (Book book : books) {if (book.getTitle().equalsIgnoreCase(title)) {JTextField titleField = new JTextField(book.getTitle());JTextField authorField = new JTextField(book.getAuthor());JTextField yearField = new JTextField(book.getYear());JTextField genreField = new JTextField(String.join(",", book.getGenres()));JTextField imagePathField = new JTextField(book.getImagePath());JTextArea description = new JTextArea(book.getDescription());description.setPreferredSize(new Dimension(200, 100));Object[] inputFields = {"Title:", titleField, "Author:", authorField, "Year:", yearField,"Genres (comma-separated):", genreField, "Image Path:", imagePathField,"Descriptoion:", new JScrollPane(description)};if (JOptionPane.showConfirmDialog(frame, inputFields, "Edit Book", JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION) {book.genres = Arrays.asList(genreField.getText().split(","));// books.set(books.indexOf(book), new Book(titleField.getText(), authorField.getText(), yearField.getText(), book.genres, imagePathField.getText()));book.setTitle(titleField.getText());book.setAuthor(authorField.getText());book.setYear(yearField.getText());book.setGenres(Arrays.asList(genreField.getText().split(",")));book.setImagePath(imagePathField.getText());book.setDescription(description.getText());updateGridPanel();}return;}}JOptionPane.showMessageDialog(frame, "Book not found!");}}class DeleteBookListener implements ActionListener {public void actionPerformed(ActionEvent e) {String title = JOptionPane.showInputDialog(frame, "Enter the title of the book to delete:");if (title == null || title.isEmpty()) return;books.removeIf(book -> book.getTitle().equalsIgnoreCase(title));updateGridPanel();}}

Comments
Post a Comment