/*
- Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
- Click nbfs://nbhost/SystemFileSystem/Templates/GUIForms/JFrame.java to edit this template
*/
package lb.librarysystem;
import java.awt.CardLayout;
/**
*
-
@author Jayden Ryan Gurung
*/
public class LibraryGUI extends javax.swing.JFrame {private Library myLibrary;
private UserTableModel userTableModel;
private BookTableModel bookTableModel;/**
-
Creates new form LibraryGUI
*/
public LibraryGUI() {
myLibrary = new Library(); // Initialize the library
userTableModel = new UserTableModel(new LibraryUser[0]); // Initialize the user table model
bookTableModel = new BookTableModel(new Book[0]);initComponents();
addTestUsers();
updateUserTable();
}
/**
-
This method is called from within the constructor to initialize the form.
-
WARNING: Do NOT modify this code. The content of this method is always
-
regenerated by the Form Editor.
*/
@SuppressWarnings(“unchecked”)
//
private void initComponents() {Users = new javax.swing.JButton();
Books = new javax.swing.JButton();
parentPanel = new javax.swing.JPanel();
userPanel = new javax.swing.JPanel();
jScrollPane2 = new javax.swing.JScrollPane();
UserTableModel = new javax.swing.JTable();
editButton = new javax.swing.JButton();
editedUser = new javax.swing.JTextField();
addUserButton = new javax.swing.JButton();
removeUserButton = new javax.swing.JButton();
bookPanel = new javax.swing.JPanel();
jScrollPane1 = new javax.swing.JScrollPane();
jTable1 = new javax.swing.JTable();
editedBook = new javax.swing.JTextField();
addBookButton = new javax.swing.JButton();
removeBookButton = new javax.swing.JButton();
editBookButton = new javax.swing.JButton();
jSlider1 = new javax.swing.JSlider();setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
Users.setBackground(new java.awt.Color(153, 153, 255));
Users.setText(“Users”);
Users.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
UsersActionPerformed(evt);
}
});Books.setBackground(new java.awt.Color(153, 255, 153));
Books.setText(“Books”);
Books.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
BooksActionPerformed(evt);
}
});parentPanel.setBackground(new java.awt.Color(153, 153, 255));
parentPanel.setLayout(new java.awt.CardLayout());userPanel.setBackground(new java.awt.Color(153, 153, 255));
UserTableModel.setAutoCreateRowSorter(true);
UserTableModel.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{null, null, null, null},
{null, null, null, null},
{null, null, null, null},
{null, null, null, null}
},
new String [] {
“Title 1”, “Title 2”, “Title 3”, “Title 4”
}
));
jScrollPane2.setViewportView(UserTableModel);
UserTableModel.getAccessibleContext().setAccessibleName(“UserTableModel”);
UserTableModel.getAccessibleContext().setAccessibleDescription(“”);
UserTableModel.getAccessibleContext().setAccessibleParent(UserTableModel);editButton.setText(“Edit”);
editButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
editButtonActionPerformed(evt);
}
});editedUser.setText(“Username Here”);
editedUser.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
editedUserActionPerformed(evt);
}
});addUserButton.setText(“Add”);
addUserButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
addUserButtonActionPerformed(evt);
}
});removeUserButton.setText(“Remove”);
removeUserButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
removeUserButtonActionPerformed(evt);
}
});javax.swing.GroupLayout userPanelLayout = new javax.swing.GroupLayout(userPanel);
userPanel.setLayout(userPanelLayout);
userPanelLayout.setHorizontalGroup(
userPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(userPanelLayout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 326, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(userPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(userPanelLayout.createSequentialGroup()
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(userPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(userPanelLayout.createSequentialGroup()
.addComponent(editedUser)
.addGap(22, 22, 22))
.addGroup(userPanelLayout.createSequentialGroup()
.addComponent(removeUserButton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 48, Short.MAX_VALUE)
.addComponent(editButton)
.addGap(12, 12, 12))))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, userPanelLayout.createSequentialGroup()
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(addUserButton)
.addGap(72, 72, 72))))
);
userPanelLayout.setVerticalGroup(
userPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(userPanelLayout.createSequentialGroup()
.addGap(39, 39, 39)
.addComponent(editedUser, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 20, Short.MAX_VALUE)
.addComponent(addUserButton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(userPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(removeUserButton)
.addComponent(editButton))
.addGap(215, 215, 215))
.addGroup(userPanelLayout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
.addContainerGap())
);parentPanel.add(userPanel, “userPanel”);
bookPanel.setBackground(new java.awt.Color(153, 255, 153));
jTable1.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{null, null, null, null},
{null, null, null, null},
{null, null, null, null},
{null, null, null, null}
},
new String [] {
“Title 1”, “Title 2”, “Title 3”, “Title 4”
}
));
jScrollPane1.setViewportView(jTable1);editedBook.setText(“Book title here”);
editedBook.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
editedBookActionPerformed(evt);
}
});addBookButton.setText(“Add”);
removeBookButton.setText(“Remove”);
editBookButton.setText(“Edit”);
javax.swing.GroupLayout bookPanelLayout = new javax.swing.GroupLayout(bookPanel);
bookPanel.setLayout(bookPanelLayout);
bookPanelLayout.setHorizontalGroup(
bookPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(bookPanelLayout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 329, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(bookPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(bookPanelLayout.createSequentialGroup()
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(bookPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(editedBook, javax.swing.GroupLayout.PREFERRED_SIZE, 184, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(bookPanelLayout.createSequentialGroup()
.addComponent(addBookButton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(removeBookButton))))
.addGroup(bookPanelLayout.createSequentialGroup()
.addGap(68, 68, 68)
.addComponent(editBookButton)))
.addContainerGap(18, Short.MAX_VALUE))
);
bookPanelLayout.setVerticalGroup(
bookPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(bookPanelLayout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
.addContainerGap())
.addGroup(bookPanelLayout.createSequentialGroup()
.addGap(43, 43, 43)
.addComponent(editedBook, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(26, 26, 26)
.addGroup(bookPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(addBookButton)
.addComponent(removeBookButton))
.addGap(28, 28, 28)
.addComponent(editBookButton)
.addContainerGap(194, Short.MAX_VALUE))
);parentPanel.add(bookPanel, “bookPanel”);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(34, 34, 34)
.addComponent(Users)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jSlider1, javax.swing.GroupLayout.PREFERRED_SIZE, 162, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(87, 87, 87)
.addComponent(Books)
.addGap(61, 61, 61))
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(parentPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(28, 28, 28)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(Users)
.addComponent(Books)
.addComponent(jSlider1, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(21, 21, 21)
.addComponent(parentPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);pack();
}//
private void UsersActionPerformed(java.awt.event.ActionEvent evt) {
CardLayout card = (CardLayout) parentPanel.getLayout();
card.show(parentPanel, “userPanel”);}
private void BooksActionPerformed(java.awt.event.ActionEvent evt) {
CardLayout card = (CardLayout) parentPanel.getLayout();
card.show(parentPanel, “bookPanel”);
}private void editButtonActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}private void editedUserActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}private void removeUserButtonActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}private void editedBookActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}private void addUserButtonActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
String username = editedUser.getText();
LibraryUser newUser = new LibraryUser(username);
newUser.setEmail(username + “@gmail.com “);
myLibrary.addUser(newUser);
updateUserTable();
}private void addTestUsers() {
String[] names = {“Kanye”, “Jonathan”, “William”, “Aryan”, “Abhinav”, “Dustin”};
for (int i = 0; i < 6; i++) {
LibraryUser newUser = new LibraryUser(names[i]);
newUser.setEmail(names[i] + “@gmail.com”);
myLibrary.addUser(newUser);
}
}private void updateUserTable()
{
userTableModel.updateTable(myLibrary.getUsers());
}/**
-
@param args the command line arguments
/
public static void main(String args[]) {
/ Set the Nimbus look and feel /
//
/ If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.- For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if (“Nimbus”.equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(LibraryGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(LibraryGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(LibraryGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(LibraryGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
new LibraryGUI().setVisible(true);
}
}); - For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
}
// Variables declaration – do not modify
private javax.swing.JButton Books;
private javax.swing.JTable UserTableModel;
private javax.swing.JButton Users;
private javax.swing.JButton addBookButton;
private javax.swing.JButton addUserButton;
private javax.swing.JPanel bookPanel;
private javax.swing.JButton editBookButton;
private javax.swing.JButton editButton;
private javax.swing.JTextField editedBook;
private javax.swing.JTextField editedUser;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JSlider jSlider1;
private javax.swing.JTable jTable1;
private javax.swing.JPanel parentPanel;
private javax.swing.JButton removeBookButton;
private javax.swing.JButton removeUserButton;
private javax.swing.JPanel userPanel;
// End of variables declaration
} -
Above is the code for my GUI. If the code of any other classes such as the LibraryUser class, library class, book class etc is needed I can provide it. Everytime I try to run the GUI, my IDE gets stuck loading at 50% and stays like that. However, it returns no compilation errors. What’s wrong with it?
Tried asking GPT 4o and Google Gemini but they didnt really help.
suki is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.