content: 
  import java.awt.Color;
  import java.sql.Connection;
  import java.sql.SQLException;
  import java.util.logging.Level;
  import java.util.logging.Logger;
  import javax.swing.JOptionPane;
  
  /*
   * 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
   */
  
  /**
   *
   * @author ahmed
   */
  public class UpdateDepartment extends javax.swing.JFrame {
  
      /**
       * Creates new form UpdateDepartment
       */
      public UpdateDepartment() {
          initComponents();
          this.setLocationRelativeTo(null);
          Building.setVisible(false);
          DepartmentName.setVisible(false);
          
      }
  
      /**
       * 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")
      // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
      private void initComponents() {
  
          jPanel1 = new javax.swing.JPanel();
          Building = new javax.swing.JPanel();
          build = new javax.swing.JTextField();
          BuildingUpdateButton = new javax.swing.JButton();
          DepartmentName = new javax.swing.JPanel();
          Department_name = new javax.swing.JTextField();
          DepartmentNameupdate = new javax.swing.JButton();
          BuildingButton = new javax.swing.JPanel();
          a5 = new javax.swing.JLabel();
          Dept_id = new javax.swing.JTextField();
          jButton8 = new javax.swing.JButton();
          DepartmentNamebutton = new javax.swing.JPanel();
          a6 = new javax.swing.JLabel();
          jLabel2 = new javax.swing.JLabel();
          jButton10 = new javax.swing.JButton();
  
          setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
          setResizable(false);
  
          jPanel1.setBackground(new java.awt.Color(0, 64, 128));
          jPanel1.setPreferredSize(new java.awt.Dimension(572, 500));
  
          Building.setBackground(new java.awt.Color(173, 216, 230));
  
          build.setText("Enter new Building");
          build.addActionListener(new java.awt.event.ActionListener() {
              public void actionPerformed(java.awt.event.ActionEvent evt) {
                  buildActionPerformed(evt);
              }
          });
  
          BuildingUpdateButton.setBackground(new java.awt.Color(0, 64, 128));
          BuildingUpdateButton.setForeground(new java.awt.Color(255, 255, 255));
          BuildingUpdateButton.setText("Enter");
          BuildingUpdateButton.addActionListener(new java.awt.event.ActionListener() {
              public void actionPerformed(java.awt.event.ActionEvent evt) {
                  BuildingUpdateButtonActionPerformed(evt);
              }
          });
  
          javax.swing.GroupLayout BuildingLayout = new javax.swing.GroupLayout(Building);
          Building.setLayout(BuildingLayout);
          BuildingLayout.setHorizontalGroup(
              BuildingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addGroup(BuildingLayout.createSequentialGroup()
                  .addGap(25, 25, 25)
                  .addGroup(BuildingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                      .addComponent(BuildingUpdateButton)
                      .addComponent(build, javax.swing.GroupLayout.PREFERRED_SIZE, 225, javax.swing.GroupLayout.PREFERRED_SIZE))
                  .addContainerGap(33, Short.MAX_VALUE))
          );
          BuildingLayout.setVerticalGroup(
              BuildingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addGroup(BuildingLayout.createSequentialGroup()
                  .addGap(45, 45, 45)
                  .addComponent(build, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                  .addComponent(BuildingUpdateButton)
                  .addContainerGap(11, Short.MAX_VALUE))
          );
  
          DepartmentName.setBackground(new java.awt.Color(173, 216, 230));
  
          Department_name.setText("New Department Name");
  
          DepartmentNameupdate.setBackground(new java.awt.Color(0, 64, 128));
          DepartmentNameupdate.setForeground(new java.awt.Color(255, 255, 255));
          DepartmentNameupdate.setText("Enter");
          DepartmentNameupdate.addActionListener(new java.awt.event.ActionListener() {
              public void actionPerformed(java.awt.event.ActionEvent evt) {
                  DepartmentNameupdateActionPerformed(evt);
              }
          });
  
          javax.swing.GroupLayout DepartmentNameLayout = new javax.swing.GroupLayout(DepartmentName);
          DepartmentName.setLayout(DepartmentNameLayout);
          DepartmentNameLayout.setHorizontalGroup(
              DepartmentNameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addGroup(DepartmentNameLayout.createSequentialGroup()
                  .addGap(19, 19, 19)
                  .addGroup(DepartmentNameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                      .addComponent(DepartmentNameupdate)
                      .addComponent(Department_name, javax.swing.GroupLayout.PREFERRED_SIZE, 225, javax.swing.GroupLayout.PREFERRED_SIZE))
                  .addContainerGap(39, Short.MAX_VALUE))
          );
          DepartmentNameLayout.setVerticalGroup(
              DepartmentNameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addGroup(DepartmentNameLayout.createSequentialGroup()
                  .addGap(47, 47, 47)
                  .addComponent(Department_name, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                  .addComponent(DepartmentNameupdate)
                  .addContainerGap(14, Short.MAX_VALUE))
          );
  
          BuildingButton.setBackground(new java.awt.Color(0, 64, 128));
          BuildingButton.addMouseListener(new java.awt.event.MouseAdapter() {
              public void mouseEntered(java.awt.event.MouseEvent evt) {
                  BuildingButtonMouseEntered(evt);
              }
              public void mouseExited(java.awt.event.MouseEvent evt) {
                  BuildingButtonMouseExited(evt);
              }
              public void mousePressed(java.awt.event.MouseEvent evt) {
                  BuildingButtonMousePressed(evt);
              }
          });
  
          a5.setForeground(new java.awt.Color(255, 255, 255));
          a5.setText("Update Building");
  
          javax.swing.GroupLayout BuildingButtonLayout = new javax.swing.GroupLayout(BuildingButton);
          BuildingButton.setLayout(BuildingButtonLayout);
          BuildingButtonLayout.setHorizontalGroup(
              BuildingButtonLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, BuildingButtonLayout.createSequentialGroup()
                  .addContainerGap(23, Short.MAX_VALUE)
                  .addComponent(a5)
                  .addGap(39, 39, 39))
          );
          BuildingButtonLayout.setVerticalGroup(
              BuildingButtonLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addGroup(BuildingButtonLayout.createSequentialGroup()
                  .addContainerGap()
                  .addComponent(a5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                  .addContainerGap())
          );
  
          Dept_id.setText("Department ID");
  
          jButton8.setBackground(new java.awt.Color(0, 64, 128));
          jButton8.setForeground(new java.awt.Color(255, 255, 255));
          jButton8.setText("Enter");
  
          DepartmentNamebutton.setBackground(new java.awt.Color(0, 64, 128));
          DepartmentNamebutton.addMouseListener(new java.awt.event.MouseAdapter() {
              public void mouseEntered(java.awt.event.MouseEvent evt) {
                  DepartmentNamebuttonMouseEntered(evt);
              }
              public void mouseExited(java.awt.event.MouseEvent evt) {
                  DepartmentNamebuttonMouseExited(evt);
              }
              public void mousePressed(java.awt.event.MouseEvent evt) {
                  DepartmentNamebuttonMousePressed(evt);
              }
          });
  
          a6.setForeground(new java.awt.Color(255, 255, 255));
          a6.setText("Update Department Name");
  
          javax.swing.GroupLayout DepartmentNamebuttonLayout = new javax.swing.GroupLayout(DepartmentNamebutton);
          DepartmentNamebutton.setLayout(DepartmentNamebuttonLayout);
          DepartmentNamebuttonLayout.setHorizontalGroup(
              DepartmentNamebuttonLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addGroup(DepartmentNamebuttonLayout.createSequentialGroup()
                  .addGap(14, 14, 14)
                  .addComponent(a6)
                  .addContainerGap(25, Short.MAX_VALUE))
          );
          DepartmentNamebuttonLayout.setVerticalGroup(
              DepartmentNamebuttonLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addGroup(DepartmentNamebuttonLayout.createSequentialGroup()
                  .addContainerGap()
                  .addComponent(a6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                  .addContainerGap())
          );
  
          jLabel2.setIcon(new javax.swing.ImageIcon("C:\\Users\\ahmed\\OneDrive\\Desktop\\download-removebg-preview (1) - Copy.png")); // NOI18N
  
          jButton10.setBackground(new java.awt.Color(0, 64, 128));
          jButton10.setForeground(new java.awt.Color(255, 255, 255));
          jButton10.setText("back");
          jButton10.addMouseListener(new java.awt.event.MouseAdapter() {
              public void mousePressed(java.awt.event.MouseEvent evt) {
                  jButton10MousePressed(evt);
              }
          });
  
          javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
          jPanel1.setLayout(jPanel1Layout);
          jPanel1Layout.setHorizontalGroup(
              jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addGroup(jPanel1Layout.createSequentialGroup()
                  .addContainerGap()
                  .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                      .addGroup(jPanel1Layout.createSequentialGroup()
                          .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                              .addGroup(jPanel1Layout.createSequentialGroup()
                                  .addComponent(Dept_id, javax.swing.GroupLayout.PREFERRED_SIZE, 225, javax.swing.GroupLayout.PREFERRED_SIZE)
                                  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                  .addComponent(jButton8))
                              .addComponent(DepartmentName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                          .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                          .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                              .addComponent(jLabel2)
                              .addComponent(jButton10)
                              .addGroup(jPanel1Layout.createSequentialGroup()
                                  .addGap(6, 6, 6)
                                  .addComponent(BuildingButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                      .addGroup(jPanel1Layout.createSequentialGroup()
                          .addComponent(Building, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                          .addGap(24, 24, 24)
                          .addComponent(DepartmentNamebutton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                  .addContainerGap(25, Short.MAX_VALUE))
          );
          jPanel1Layout.setVerticalGroup(
              jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                  .addContainerGap()
                  .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                      .addGroup(jPanel1Layout.createSequentialGroup()
                          .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                              .addComponent(Dept_id, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                              .addComponent(jButton8))
                          .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                          .addComponent(DepartmentName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                          .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                          .addComponent(Building, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                      .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                          .addComponent(jButton10)
                          .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                          .addComponent(jLabel2)
                          .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                          .addComponent(BuildingButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                          .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                          .addComponent(DepartmentNamebutton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                  .addContainerGap(18, Short.MAX_VALUE))
          );
  
          javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
          getContentPane().setLayout(layout);
          layout.setHorizontalGroup(
              layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 519, Short.MAX_VALUE)
          );
          layout.setVerticalGroup(
              layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 284, Short.MAX_VALUE)
          );
  
          pack();
      }// </editor-fold>//GEN-END:initComponents
  
      private void buildActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buildActionPerformed
          // TODO add your handling code here:
      }//GEN-LAST:event_buildActionPerformed
  
      private void BuildingButtonMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_BuildingButtonMouseEntered
          // TODO add your handling code here:
          a5.setForeground(new java.awt.Color(173, 216, 230));
      }//GEN-LAST:event_BuildingButtonMouseEntered
  
      private void BuildingButtonMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_BuildingButtonMouseExited
          // TODO add your handling code here:
          a5.setForeground(Color.WHITE);
      }//GEN-LAST:event_BuildingButtonMouseExited
  
      private void BuildingButtonMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_BuildingButtonMousePressed
          // TODO add your handling code here:
          Building.setVisible(true);
          DepartmentName.setVisible(false);
      }//GEN-LAST:event_BuildingButtonMousePressed
  
      private void DepartmentNamebuttonMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_DepartmentNamebuttonMouseEntered
          // TODO add your handling code here:
          a6.setForeground(new java.awt.Color(173, 216, 230));
      }//GEN-LAST:event_DepartmentNamebuttonMouseEntered
  
      private void DepartmentNamebuttonMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_DepartmentNamebuttonMouseExited
          // TODO add your handling code here:
          a6.setForeground(Color.WHITE);
      }//GEN-LAST:event_DepartmentNamebuttonMouseExited
  
      private void DepartmentNamebuttonMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_DepartmentNamebuttonMousePressed
          // TODO add your handling code here:
          Building.setVisible(false);
          DepartmentName.setVisible(true);
      }//GEN-LAST:event_DepartmentNamebuttonMousePressed
  
      private void jButton10MousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton10MousePressed
          // TODO add your handling code here:
          systemManag s = new systemManag();
          s.setVisible(true);
          s.setLocationRelativeTo(null);//center
          this.dispose();
      }//GEN-LAST:event_jButton10MousePressed
  
      private void DepartmentNameupdateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_DepartmentNameupdateActionPerformed
          // TODO add your handling code here:
              String department_name = Department_name.getText();
              int Department_id =Integer.parseInt(Dept_id.getText());
  
  // Database operation
          try (Connection connection = ConnectToDB.getConnection(); java.sql.PreparedStatement preparedStatement = connection.prepareStatement(
                  "UPDATE Dept SET Dept_Name = ? WHERE Dept_ID = ?;")) {
  
              // Set values for the prepared statement
              preparedStatement.setString(1, department_name);
              preparedStatement.setInt(2, Department_id);
  
              // Execute the insert operation
              preparedStatement.executeUpdate();
  
              // Success message
              JOptionPane.showMessageDialog(this, "Department Name Update Successfully");
  
          } catch (SQLException e) {
              Logger.getLogger(SignUp.class.getName()).log(Level.SEVERE, "Database error: ", e);
              JOptionPane.showMessageDialog(this, "An error occurred while saving This data. Please try again.");
          }
      }//GEN-LAST:event_DepartmentNameupdateActionPerformed
  
      private void BuildingUpdateButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BuildingUpdateButtonActionPerformed
          // TODO add your handling code here:
              // TODO add your handling code here:
              String building = build.getText();
              int Department_id =Integer.parseInt(Dept_id.getText());
  
  // Database operation
          try (Connection connection = ConnectToDB.getConnection(); java.sql.PreparedStatement preparedStatement = connection.prepareStatement(
                  "UPDATE Dept SET Building = ? WHERE Dept_ID = ?;")) {
  
              // Set values for the prepared statement
              preparedStatement.setString(1, building);
              preparedStatement.setInt(2, Department_id);
  
              // Execute the insert operation
              preparedStatement.executeUpdate();
  
              // Success message
              JOptionPane.showMessageDialog(this, "Department Building Update Successfully");
  
          } catch (SQLException e) {
              Logger.getLogger(SignUp.class.getName()).log(Level.SEVERE, "Database error: ", e);
              JOptionPane.showMessageDialog(this, "An error occurred while saving This data. Please try again.");
          }
      }//GEN-LAST:event_BuildingUpdateButtonActionPerformed
  
      /**
       * @param args the command line arguments
       */
      public static void main(String args[]) {
          /* Set the Nimbus look and feel */
          //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
          /* 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(UpdateDepartment.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
          } catch (InstantiationException ex) {
              java.util.logging.Logger.getLogger(UpdateDepartment.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
          } catch (IllegalAccessException ex) {
              java.util.logging.Logger.getLogger(UpdateDepartment.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
          } catch (javax.swing.UnsupportedLookAndFeelException ex) {
              java.util.logging.Logger.getLogger(UpdateDepartment.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
          }
          //</editor-fold>
  
          /* Create and display the form */
          java.awt.EventQueue.invokeLater(new Runnable() {
              public void run() {
                  new UpdateDepartment().setVisible(true);
              }
          });
      }
  
      // Variables declaration - do not modify//GEN-BEGIN:variables
      private javax.swing.JPanel Building;
      private javax.swing.JPanel BuildingButton;
      private javax.swing.JButton BuildingUpdateButton;
      private javax.swing.JPanel DepartmentName;
      private javax.swing.JPanel DepartmentNamebutton;
      private javax.swing.JButton DepartmentNameupdate;
      private javax.swing.JTextField Department_name;
      private javax.swing.JTextField Dept_id;
      private javax.swing.JLabel a5;
      private javax.swing.JLabel a6;
      private javax.swing.JTextField build;
      private javax.swing.JButton jButton10;
      private javax.swing.JButton jButton8;
      private javax.swing.JLabel jLabel2;
      private javax.swing.JPanel jPanel1;
      // End of variables declaration//GEN-END:variables
  }
  