// Fees update method
  private void updateFeesData(long id) {
    String columns[] = {"Course", "Fees Payed", "Total fees", "Installments"};
    try {
      Database db = new Database();

      panel_7.removeAll();

      feestablemodel = new MyTableModel(db.getFeeData(id), columns);

      feestable = new JTable(feestablemodel);
      feestable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
      feestable.getSelectionModel().addListSelectionListener(this);

      feesscrollpane = new JScrollPane(feestable);
      panel_7.add(feesscrollpane);

      // change fees payed label
      feespayedlabel.setText("Fees Payed");
      feesduelabel.setText("Fees Due");
      totalfeeslabel.setText("Total Fees");

      panel_7.revalidate();
    } catch (Exception e) {
      JOptionPane.showMessageDialog(this, e.getMessage(), null, JOptionPane.ERROR_MESSAGE);
    }
  }
  // Method to update Table and related components
  private void update() {
    Database db = new Database();
    String column[] = {
      "ID",
      "NAME",
      "GENDER",
      "GUARDIAN_ROLE",
      "GUARDIAN_NAME",
      "PRESENT_ADDRESS",
      "PRESENT_CITY",
      "PRESENT_PHONE"
    };

    try {
      // Update table
      if (searchcombobox.getSelectedIndex() == 0 && allfieldcheckbox.isSelected()) {
        mytablemodel = new MyTableModel(db.getAllStudent(), db.getColumnNameFromStudent());
      } else if (searchcombobox.getSelectedIndex() == 0 && !allfieldcheckbox.isSelected()) {
        mytablemodel = new MyTableModel(db.getSomeFieldsFromStudent(), column);
      } else if (searchcombobox.getSelectedIndex() == 1 && allfieldcheckbox.isSelected()) {
        String query =
            "SELECT * FROM Student WHERE NAME = \'" + searchtextfield.getText().trim() + "\'";
        mytablemodel = new MyTableModel(db.getData(query), db.getColumnNameFromStudent());
      } else if (searchcombobox.getSelectedIndex() == 1 && !allfieldcheckbox.isSelected()) {
        String query =
            "SELECT ID, NAME, GENDER, GUARDIAN_ROLE, GUARDIAN_NAME, PRESENT_ADDRESS, PRESENT_CITY, PRESENT_PHONE FROM Student WHERE NAME = \'"
                + searchtextfield.getText().trim()
                + "\'";
        mytablemodel = new MyTableModel(db.getData(query), column);
      } else if (searchcombobox.getSelectedIndex() == 2 && allfieldcheckbox.isSelected()) {
        String query =
            "SELECT * FROM Student WHERE GUARDIAN_NAME = \'"
                + searchtextfield.getText().trim()
                + "\'";
        mytablemodel = new MyTableModel(db.getData(query), db.getColumnNameFromStudent());
      } else if (searchcombobox.getSelectedIndex() == 2 && !allfieldcheckbox.isSelected()) {
        String query =
            "SELECT ID, NAME, GENDER, GUARDIAN_ROLE, GUARDIAN_NAME, PRESENT_ADDRESS, PRESENT_CITY, PRESENT_PHONE FROM Student WHERE GUARDIAN_NAME = \'"
                + searchtextfield.getText().trim()
                + "\'";
        mytablemodel = new MyTableModel(db.getData(query), column);
      } else if (searchcombobox.getSelectedIndex() == 3 && allfieldcheckbox.isSelected()) {
        String query =
            "SELECT * FROM Student WHERE ID = ANY(SELECT SID FROM Fee WHERE CID = ANY(SELECT ID FROM CourseInfo WHERE NAME = \'"
                + searchtextfield.getText().trim()
                + "\'))";
        mytablemodel = new MyTableModel(db.getData(query), db.getColumnNameFromStudent());
      } else if (searchcombobox.getSelectedIndex() == 3 && !allfieldcheckbox.isSelected()) {
        String query =
            "SELECT ID, NAME, GENDER, GUARDIAN_ROLE, GUARDIAN_NAME, PRESENT_ADDRESS, PRESENT_CITY, PRESENT_PHONE FROM Student WHERE ID = ANY(SELECT SID FROM Fee WHERE CID = ANY(SELECT ID FROM CourseInfo WHERE NAME = \'"
                + searchtextfield.getText().trim()
                + "\'))";
        mytablemodel = new MyTableModel(db.getData(query), column);
      } else if (searchcombobox.getSelectedIndex() == 4 && allfieldcheckbox.isSelected()) {
        String query =
            "SELECT * FROM Student WHERE ID = ANY(SELECT SID FROM Fee WHERE TOTAL_FEES - FEES_PAYED >= 0)";
        mytablemodel = new MyTableModel(db.getData(query), db.getColumnNameFromStudent());
      } else {
        String query =
            "SELECT ID, NAME, GENDER, GUARDIAN_ROLE, GUARDIAN_NAME, PRESENT_ADDRESS, PRESENT_CITY, PRESENT_PHONE FROM Student WHERE ID = ANY(SELECT SID FROM Fee WHERE TOTAL_FEES - FEES_PAYED >= 0)";
        mytablemodel = new MyTableModel(db.getData(query), column);
      }

      table = new JTable(mytablemodel);
      table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
      // Add list selection listener to table
      table.getSelectionModel().addListSelectionListener(this);

      TableColumn col = null;
      for (int i = 3; i < table.getColumnCount(); i++) {
        col = table.getColumnModel().getColumn(i);
        col.setPreferredWidth(200);
      }

      scrollpane = new JScrollPane(table);

      panel_3.removeAll();
      panel_3.add(scrollpane);

      // Update total student label
      int total = db.getTotalStudent();
      totalstudentlabel.setText("Total Student = " + total);

      // Clear search combo box
      searchtextfield.setText("");

      this.revalidate();
    } catch (Exception e) {
      JOptionPane.showMessageDialog(this, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
    }
  }
  private void makeGUI() {
    // Set Frames properties
    this.setTitle("Search And Edit Student");
    this.setSize(700, 500);
    this.setLocationRelativeTo(null);
    this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

    // Add components to panel_1
    FlowLayout layout = new FlowLayout();
    layout.setAlignment(FlowLayout.LEFT);
    panel_1.setLayout(layout);
    panel_1.add(searchcombobox);
    panel_1.add(searchtextfield);
    panel_1.add(searchbutton);
    panel_1.add(allfieldcheckbox);
    panel_1.setBackground(Color.WHITE);

    // Add panel_1 to frame
    this.add(panel_1, BorderLayout.PAGE_START);

    // Add components to panel_2
    panel_2.add(totalstudentlabel);
    panel_2.setBackground(Color.WHITE);

    // Add panel_2 to frame
    this.add(panel_2, BorderLayout.PAGE_END);

    // Add components to panel_3
    panel_3.setLayout(new GridLayout(1, 0));

    // Design panel_5
    GridBagLayout gbl = new GridBagLayout();
    GridBagConstraints c = new GridBagConstraints();
    c.weightx = 1;
    c.weighty = 1;
    c.fill = GridBagConstraints.BOTH;

    panel_5.setLayout(gbl);

    c.gridx = 0;
    c.gridy = 0;
    c.gridheight = 4;
    c.gridwidth = GridBagConstraints.REMAINDER;
    panel_5.add(panel_3, c);

    c.gridx = 0;
    c.gridy = 5;
    c.gridheight = 2;
    c.gridwidth = GridBagConstraints.REMAINDER;
    panel_5.add(panel_4, c);

    // Add components to panel_4
    panel_4.setLayout(new GridLayout(1, 2));
    panel_4.add(panel_6); // Lower Left
    panel_4.add(panel_7); // Lower Right

    // Design panel 6
    SpringLayout sl = new SpringLayout();
    panel_6.setLayout(sl);

    sl.putConstraint(SpringLayout.WEST, feespayedlabel, 2, SpringLayout.WEST, panel_6);
    sl.putConstraint(SpringLayout.NORTH, feespayedlabel, 2, SpringLayout.NORTH, panel_6);

    sl.putConstraint(SpringLayout.WEST, addfeestextfield, 2, SpringLayout.EAST, feespayedlabel);
    sl.putConstraint(SpringLayout.NORTH, addfeestextfield, 2, SpringLayout.NORTH, panel_6);

    sl.putConstraint(SpringLayout.WEST, addfeesbutton, 2, SpringLayout.EAST, addfeestextfield);
    sl.putConstraint(SpringLayout.NORTH, addfeesbutton, 2, SpringLayout.NORTH, panel_6);

    sl.putConstraint(SpringLayout.WEST, feesduelabel, 2, SpringLayout.WEST, panel_6);
    sl.putConstraint(SpringLayout.NORTH, feesduelabel, 2, SpringLayout.SOUTH, addfeesbutton);

    sl.putConstraint(SpringLayout.WEST, totalfeeslabel, 2, SpringLayout.WEST, panel_6);
    sl.putConstraint(SpringLayout.NORTH, totalfeeslabel, 2, SpringLayout.SOUTH, feesduelabel);

    sl.putConstraint(SpringLayout.WEST, coursecombobox, 2, SpringLayout.WEST, panel_6);
    sl.putConstraint(SpringLayout.NORTH, coursecombobox, 3, SpringLayout.SOUTH, totalfeeslabel);

    sl.putConstraint(SpringLayout.WEST, spinner, 2, SpringLayout.EAST, coursecombobox);
    sl.putConstraint(SpringLayout.NORTH, spinner, 3, SpringLayout.SOUTH, totalfeeslabel);

    sl.putConstraint(SpringLayout.WEST, addcoursebutton, 2, SpringLayout.WEST, panel_6);
    sl.putConstraint(SpringLayout.NORTH, addcoursebutton, 3, SpringLayout.SOUTH, coursecombobox);

    panel_6.add(feespayedlabel);
    panel_6.add(addfeestextfield);
    panel_6.add(addfeesbutton);
    panel_6.add(feesduelabel);
    panel_6.add(totalfeeslabel);
    panel_6.add(coursecombobox);
    panel_6.add(spinner);
    panel_6.add(addcoursebutton);

    // Set panel 7 layout
    panel_7.setLayout(new GridLayout(1, 0));
    panel_7.setBackground(Color.WHITE);

    // Add panel_5 to frame
    this.add(panel_5);

    update();

    // Show frame
    this.validate();
    this.setVisible(true);
  }