content: 
  import java.sql.Connection;
  import java.sql.PreparedStatement;
  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 SignUp extends javax.swing.JFrame {
  
      /**
       * Creates new form SignUp
       */
      public SignUp() {
          initComponents();
          this.setLocationRelativeTo(null);
  
      }
  
      /**
       * 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();
          Instructor_button = new javax.swing.JButton();
          Student_button = new javax.swing.JButton();
          password = new javax.swing.JTextField();
          jButton3 = new javax.swing.JButton();
          jPanel3 = new javax.swing.JPanel();
          jPanel2 = new javax.swing.JPanel();
          jLabel1 = new javax.swing.JLabel();
          confirmpassword = new javax.swing.JTextField();
          department = new javax.swing.JTextField();
          jLabel2 = new javax.swing.JLabel();
          name = new javax.swing.JTextField();
          national_id = new javax.swing.JTextField();
          position = new javax.swing.JTextField();
  
          setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
          setResizable(false);
  
          jPanel1.setBackground(new java.awt.Color(0, 64, 128));
  
          Instructor_button.setText("Instructor");
          Instructor_button.addMouseListener(new java.awt.event.MouseAdapter() {
              public void mouseEntered(java.awt.event.MouseEvent evt) {
                  Instructor_buttonMouseEntered(evt);
              }
              public void mousePressed(java.awt.event.MouseEvent evt) {
                  Instructor_buttonMousePressed(evt);
              }
          });
          Instructor_button.addActionListener(new java.awt.event.ActionListener() {
              public void actionPerformed(java.awt.event.ActionEvent evt) {
                  Instructor_buttonActionPerformed(evt);
              }
          });
  
          Student_button.setText("Student");
          Student_button.addMouseListener(new java.awt.event.MouseAdapter() {
              public void mouseEntered(java.awt.event.MouseEvent evt) {
                  Student_buttonMouseEntered(evt);
              }
              public void mousePressed(java.awt.event.MouseEvent evt) {
                  Student_buttonMousePressed(evt);
              }
          });
          Student_button.addActionListener(new java.awt.event.ActionListener() {
              public void actionPerformed(java.awt.event.ActionEvent evt) {
                  Student_buttonActionPerformed(evt);
              }
          });
  
          password.setText("Password");
  
          jButton3.setText("Login");
          jButton3.addMouseListener(new java.awt.event.MouseAdapter() {
              public void mousePressed(java.awt.event.MouseEvent evt) {
                  jButton3MousePressed(evt);
              }
          });
          jButton3.addActionListener(new java.awt.event.ActionListener() {
              public void actionPerformed(java.awt.event.ActionEvent evt) {
                  jButton3ActionPerformed(evt);
              }
          });
  
          jPanel3.setLayout(new java.awt.GridLayout(1, 0));
  
          jPanel2.setBackground(new java.awt.Color(255, 255, 255));
  
          jLabel1.setIcon(new javax.swing.ImageIcon("C:\\Users\\ahmed\\OneDrive\\Desktop\\R.jpeg")); // NOI18N
  
          javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
          jPanel2.setLayout(jPanel2Layout);
          jPanel2Layout.setHorizontalGroup(
              jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                  .addContainerGap(91, Short.MAX_VALUE)
                  .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 213, javax.swing.GroupLayout.PREFERRED_SIZE)
                  .addGap(80, 80, 80))
          );
          jPanel2Layout.setVerticalGroup(
              jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addGroup(jPanel2Layout.createSequentialGroup()
                  .addGap(190, 190, 190)
                  .addComponent(jLabel1)
                  .addContainerGap(178, Short.MAX_VALUE))
          );
  
          confirmpassword.setText("Confirm Password");
          confirmpassword.addActionListener(new java.awt.event.ActionListener() {
              public void actionPerformed(java.awt.event.ActionEvent evt) {
                  confirmpasswordActionPerformed(evt);
              }
          });
  
          department.setText("Department_ID");
          department.addActionListener(new java.awt.event.ActionListener() {
              public void actionPerformed(java.awt.event.ActionEvent evt) {
                  departmentActionPerformed(evt);
              }
          });
  
          jLabel2.setFont(new java.awt.Font("Segoe UI", 1, 12)); // NOI18N
          jLabel2.setForeground(new java.awt.Color(255, 255, 255));
          jLabel2.setText("I already have acount");
  
          name.setText("Name");
          name.addActionListener(new java.awt.event.ActionListener() {
              public void actionPerformed(java.awt.event.ActionEvent evt) {
                  nameActionPerformed(evt);
              }
          });
  
          national_id.setText("National ID");
          national_id.addActionListener(new java.awt.event.ActionListener() {
              public void actionPerformed(java.awt.event.ActionEvent evt) {
                  national_idActionPerformed(evt);
              }
          });
  
          position.setText("Position if your instructor");
          position.addActionListener(new java.awt.event.ActionListener() {
              public void actionPerformed(java.awt.event.ActionEvent evt) {
                  positionActionPerformed(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()
                  .addGap(31, 31, 31)
                  .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                      .addComponent(password, javax.swing.GroupLayout.PREFERRED_SIZE, 282, javax.swing.GroupLayout.PREFERRED_SIZE)
                      .addComponent(confirmpassword, javax.swing.GroupLayout.PREFERRED_SIZE, 282, javax.swing.GroupLayout.PREFERRED_SIZE)
                      .addComponent(department, javax.swing.GroupLayout.PREFERRED_SIZE, 282, javax.swing.GroupLayout.PREFERRED_SIZE)
                      .addComponent(name, javax.swing.GroupLayout.PREFERRED_SIZE, 282, javax.swing.GroupLayout.PREFERRED_SIZE)
                      .addComponent(national_id, javax.swing.GroupLayout.PREFERRED_SIZE, 282, javax.swing.GroupLayout.PREFERRED_SIZE)
                      .addGroup(jPanel1Layout.createSequentialGroup()
                          .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                              .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 128, javax.swing.GroupLayout.PREFERRED_SIZE)
                              .addComponent(Instructor_button, javax.swing.GroupLayout.PREFERRED_SIZE, 128, javax.swing.GroupLayout.PREFERRED_SIZE))
                          .addGap(18, 18, 18)
                          .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                              .addComponent(Student_button, javax.swing.GroupLayout.PREFERRED_SIZE, 128, javax.swing.GroupLayout.PREFERRED_SIZE)
                              .addComponent(jLabel2)))
                      .addComponent(position, javax.swing.GroupLayout.PREFERRED_SIZE, 282, javax.swing.GroupLayout.PREFERRED_SIZE))
                  .addGap(33, 33, 33)
                  .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                  .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                  .addContainerGap())
          );
          jPanel1Layout.setVerticalGroup(
              jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
              .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                  .addGap(39, 39, 39)
                  .addComponent(name, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                  .addComponent(department, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                  .addComponent(national_id, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                  .addComponent(password, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                  .addComponent(confirmpassword, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                  .addComponent(position, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                  .addGap(30, 30, 30)
                  .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                      .addComponent(Student_button, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)
                      .addComponent(Instructor_button, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE))
                  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                  .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                      .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)
                      .addComponent(jLabel2))
                  .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
              .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
          );
  
          javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
          getContentPane().setLayout(layout);
          layout.setHorizontalGroup(
              layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addGroup(layout.createSequentialGroup()
                  .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 727, javax.swing.GroupLayout.PREFERRED_SIZE)
                  .addGap(0, 0, Short.MAX_VALUE))
          );
          layout.setVerticalGroup(
              layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
          );
  
          pack();
      }// </editor-fold>//GEN-END:initComponents
  
      private void Instructor_buttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Instructor_buttonActionPerformed
          // TODO add your handling code here:
          // Get user inputs
          String instructorName = name.getText();
          String instructorPassword = password.getText();
          String confirmPassword = confirmpassword.getText();
          String position1 = this.position.getText();
          String instructorNation = national_id.getText();
          int departmentId;
  
  // Validate password match
          if (!instructorPassword.equals(confirmPassword)) {
              JOptionPane.showMessageDialog(this, "Passwords do not match. Please try again.");
              return; // Exit if passwords do not match
          }
          if(position1.equals("Manager"))return;
  // Validate and parse department ID
          try {
              departmentId = Integer.parseInt(department.getText());
          } catch (NumberFormatException e) {
              JOptionPane.showMessageDialog(this, "Invalid department ID. Please enter a valid number.");
              return; // Exit if department ID is invalid
          }
          
  // Database operation
          try (Connection connection = ConnectToDB.getConnection(); PreparedStatement preparedStatement = connection.prepareStatement(
                  "INSERT INTO Instructor (Instructor_ID, Instructor_Name, Instructor_Password, Instructor_National_ID, Salary, Dept_ID, position) "
                  + "VALUES (?, ?, ?, ?, ?, ?, ?);")) {
  
              // Set values for the prepared statement
              preparedStatement.setInt(1, Integer.parseInt(instructorNation));
              preparedStatement.setString(2, instructorName);
              preparedStatement.setString(3, instructorPassword);
              preparedStatement.setString(4, instructorNation);
              preparedStatement.setInt(5, 6000); // Default salary
              preparedStatement.setInt(6, departmentId);
              preparedStatement.setString(7, position1); // Corrected parameter index
  
              // Execute the insert operation
              preparedStatement.executeUpdate();
  
              // Success message
              JOptionPane.showMessageDialog(this, "Sign-up successful! Your ID: " + instructorNation + ", Password: " + instructorPassword);
  
              // Open Login screen
              Login loginScreen = new Login();
              loginScreen.setVisible(true);
              loginScreen.setLocationRelativeTo(null); // Center the window
              this.dispose(); // Close current window
  
          } catch (SQLException e) {
              Logger.getLogger(SignUp.class.getName()).log(Level.SEVERE, "Database error: ", e);
              JOptionPane.showMessageDialog(this, "An error occurred while saving your data. Please try again.");
          }
  
      }//GEN-LAST:event_Instructor_buttonActionPerformed
  
      private void Student_buttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Student_buttonActionPerformed
          // TODO add your handling code here:
          String studentName = name.getText();
          String studentPassword = password.getText();
          String confirmPassword = confirmpassword.getText();
          String studentNation = national_id.getText();
          int departmentId;
  
  // Validate password match
          if (!studentPassword.equals(confirmPassword)) {
              JOptionPane.showMessageDialog(this, "Passwords do not match. Please try again.");
              return; // Exit if passwords do not match
          }
  
  // Validate and parse department ID
          try {
              departmentId = Integer.parseInt(department.getText());
          } catch (NumberFormatException e) {
              JOptionPane.showMessageDialog(this, "Invalid department ID. Please enter a valid number.");
              return; // Exit if department ID is invalid
          }
  
  // Database operation
          try (Connection connection = ConnectToDB.getConnection(); PreparedStatement preparedStatement = connection.prepareStatement(
                  "INSERT INTO Student (Student_ID, Student_Name, Student_Password, Student_National_ID, Total_cred, Dept_ID) "
                  + "VALUES (?, ?, ?, ?, ?, ?);")) {
  
              // Set values for the prepared statement
              preparedStatement.setInt(1, Integer.parseInt(studentNation));
              preparedStatement.setString(2, studentName);
              preparedStatement.setString(3, studentPassword);
              preparedStatement.setString(4, studentNation);
              preparedStatement.setInt(5, 0); // Default total credits
              preparedStatement.setInt(6, departmentId);
  
              // Execute the insert operation
              preparedStatement.executeUpdate();
  
              // Success message
              JOptionPane.showMessageDialog(this, "Sign-up successful! Your ID: " + studentNation + ", Password: " + studentPassword);
  
              // Open Login screen
              Login loginScreen = new Login();
              loginScreen.setVisible(true);
              loginScreen.setLocationRelativeTo(null); // Center the window
              this.dispose(); // Close current window
  
          } catch (SQLException e) {
              Logger.getLogger(SignUp.class.getName()).log(Level.SEVERE, "Database error: ", e);
              JOptionPane.showMessageDialog(this, "An error occurred while saving your data. Please try again.");
          }
      }//GEN-LAST:event_Student_buttonActionPerformed
  
      private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
          // TODO add your handling code here:
          Login x = null;
          try {
              x = new Login();
          } catch (SQLException ex) {
              Logger.getLogger(SignUp.class.getName()).log(Level.SEVERE, null, ex);
          }
          x.setVisible(true);
          x.setLocationRelativeTo(null);//center
          this.dispose();
      }//GEN-LAST:event_jButton3ActionPerformed
  
      private void departmentActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_departmentActionPerformed
          // TODO add your handling code here:
      }//GEN-LAST:event_departmentActionPerformed
  
      private void confirmpasswordActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_confirmpasswordActionPerformed
          // TODO add your handling code here:
      }//GEN-LAST:event_confirmpasswordActionPerformed
  
      private void jButton3MousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton3MousePressed
          // TODO add your handling code here:
      }//GEN-LAST:event_jButton3MousePressed
  
      private void Student_buttonMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_Student_buttonMouseEntered
          // TODO add your handling code here:
  
      }//GEN-LAST:event_Student_buttonMouseEntered
  
      private void Instructor_buttonMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_Instructor_buttonMouseEntered
          // TODO add your handling code here:
      }//GEN-LAST:event_Instructor_buttonMouseEntered
  
      private void Student_buttonMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_Student_buttonMousePressed
          // TODO add your handling code here:
      }//GEN-LAST:event_Student_buttonMousePressed
  
      private void Instructor_buttonMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_Instructor_buttonMousePressed
          // TODO add your handling code here:
      }//GEN-LAST:event_Instructor_buttonMousePressed
  
      private void nameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nameActionPerformed
          // TODO add your handling code here:
      }//GEN-LAST:event_nameActionPerformed
  
      private void national_idActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_national_idActionPerformed
          // TODO add your handling code here:
      }//GEN-LAST:event_national_idActionPerformed
  
      private void positionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_positionActionPerformed
          // TODO add your handling code here:
      }//GEN-LAST:event_positionActionPerformed
  
      /**
       * @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(SignUp.class
                      .getName()).log(java.util.logging.Level.SEVERE, null, ex);
  
          } catch (InstantiationException ex) {
              java.util.logging.Logger.getLogger(SignUp.class
                      .getName()).log(java.util.logging.Level.SEVERE, null, ex);
  
          } catch (IllegalAccessException ex) {
              java.util.logging.Logger.getLogger(SignUp.class
                      .getName()).log(java.util.logging.Level.SEVERE, null, ex);
  
          } catch (javax.swing.UnsupportedLookAndFeelException ex) {
              java.util.logging.Logger.getLogger(SignUp.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 SignUp().setVisible(true);
              }
          });
      }
  
      // Variables declaration - do not modify//GEN-BEGIN:variables
      private javax.swing.JButton Instructor_button;
      private javax.swing.JButton Student_button;
      private javax.swing.JTextField confirmpassword;
      private javax.swing.JTextField department;
      private javax.swing.JButton jButton3;
      private javax.swing.JLabel jLabel1;
      private javax.swing.JLabel jLabel2;
      private javax.swing.JPanel jPanel1;
      private javax.swing.JPanel jPanel2;
      private javax.swing.JPanel jPanel3;
      private javax.swing.JTextField name;
      private javax.swing.JTextField national_id;
      private javax.swing.JTextField password;
      private javax.swing.JTextField position;
      // End of variables declaration//GEN-END:variables
  }
  