NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

package Project.Controllers;

import javax.swing.*;

import Business.Services.BookService;
import Entity.Models.Author;
import Entity.Models.Book;
public void createBook() {
JFrame frame = new JFrame("Create book");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(400, 200);

JPanel panel = new JPanel();
frame.add(panel);

panel.setLayout(null);

JLabel nameLabel = new JLabel("Enter Book name:");
nameLabel.setBounds(10, 20, 150, 25);
panel.add(nameLabel);

JTextField nameField = new JTextField(20);
nameField.setBounds(170, 20, 200, 25);
panel.add(nameField);

public class BookController {
private BookService bookService = new BookService();



// JLabel capacityLabel = new JLabel("Enter department capacity:");
// capacityLabel.setBounds(10, 50, 150, 25);
// panel.add(capacityLabel);

// JTextField capacityField = new JTextField(20);
// capacityField.setBounds(170, 50, 200, 25);
// panel.add(capacityField);

JButton createButton = new JButton("Create Book");
createButton.setBounds(10, 80, 150, 25);
panel.add(createButton);

createButton.addActionListener(e -> {
String name = nameField.getText();
Author author= new Author("d");
try {
// outcapacity = Integer.parseInt(capacity);
Book book = new Book(name,author);
if (bookService.Create(book)!=null) {
JOptionPane.showMessageDialog(frame, "Book created successfully");
} else {
JOptionPane.showMessageDialog(frame, "Failed to create Book", "Error", JOptionPane.ERROR_MESSAGE);
}
} catch (NumberFormatException ex) {
JOptionPane.showMessageDialog(frame, "Invalid capacity. Please enter a valid number", "Error", JOptionPane.ERROR_MESSAGE);
}
});

frame.setVisible(true);
}
public void deleteBook() {
JFrame frame = new JFrame("Delete book");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(400, 200);

JPanel panel = new JPanel();
frame.add(panel);

panel.setLayout(null);

JLabel titleLabel = new JLabel("Existed Books:");
titleLabel.setBounds(10, 10, 200, 25);
panel.add(titleLabel);

JTextArea departmentTextArea = new JTextArea();
departmentTextArea.setEditable(false);
JScrollPane scrollPane = new JScrollPane(departmentTextArea);
scrollPane.setBounds(10, 40, 380, 100);
panel.add(scrollPane);

JButton deleteButton = new JButton("Delete Book");
deleteButton.setBounds(10, 150, 150, 25);
panel.add(deleteButton);

JButton cancelButton = new JButton("Cancel");
cancelButton.setBounds(200, 150, 150, 25);
panel.add(cancelButton);

deleteButton.addActionListener(e -> {
String id = JOptionPane.showInputDialog(frame, "Enter Book ID to delete:");
if (id != null) {
try {
int departmentId = Integer.parseInt(id);
if (bookService.Delete(departmentId)) {
JOptionPane.showMessageDialog(frame, "Book with ID " + departmentId + " deleted successfully");
} else {
JOptionPane.showMessageDialog(frame, "Book with ID " + departmentId + " not found", "Error", JOptionPane.ERROR_MESSAGE);
}
} catch (NumberFormatException ex) {
JOptionPane.showMessageDialog(frame, "Invalid Book ID", "Error", JOptionPane.ERROR_MESSAGE);
}
}
});

cancelButton.addActionListener(e -> frame.dispose());

// departmentTextArea.setText(getAllDepartmentsAsString());

frame.setVisible(true);
}

// private String getAllDepartmentsAsString() {
// StringBuilder sb = new StringBuilder();
// for (Book department : bookService.getAll()) {
// sb.append("ID: ").append(department.getId()).append(", Name: ").append(department.getName()).append(", Capacity: ").append(department.getCapacity()).append("n");
// }
// return sb.toString();
// }

}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.