Advertisement
Gaudenz

StudentConsultationForm

Mar 13th, 2025
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 19.30 KB | None | 0 0
  1. package lyfjshs.gomis.view.students;
  2.  
  3. import javax.swing.*;
  4. import javax.swing.border.EmptyBorder;
  5. import java.awt.*;
  6. import java.awt.event.ActionEvent;
  7. import java.awt.event.ActionListener;
  8. import java.text.SimpleDateFormat;
  9. import java.util.Date;
  10. import java.util.HashMap;
  11. import java.util.Map;
  12.  
  13. import net.miginfocom.swing.MigLayout;
  14. import com.formdev.flatlaf.FlatLightLaf;
  15.  
  16. public class StudentConsultationForm extends JFrame {
  17.     private Map<String, Object> formData;
  18.     private JTextField studentNameField, gradeField, schoolField, consultantNameField, witnessesField;
  19.     private JTextField receivedField;
  20.     private JTextArea descStudentConcernArea, summaryOfGuidancePlanArea, studentStatementArea;
  21.     private JCheckBox frequentAbsencesBox, bullyingOrFightingBox, academicPerfBox, failedAssignmentsBox;
  22.     private JCheckBox misbehaviorBox, schoolRuleViolationBox, disrespectfulBox, othersBox;
  23.     private JSpinner dateTimeSpinner, dateConSpinner, followUpDateSpinner;
  24.     private JSpinner dateStudentSpinner, dateGuardianSpinner, dateAdminSpinner;
  25.  
  26.     public static void main(String[] args) {
  27.         try {
  28.             // Set the FlatLaf look and feel
  29.             UIManager.setLookAndFeel(new FlatLightLaf());
  30.         } catch (Exception e) {
  31.             System.err.println("Failed to initialize FlatLaf");
  32.         }
  33.  
  34.         SwingUtilities.invokeLater(() -> {
  35.             new StudentConsultationForm().setVisible(true);
  36.         });
  37.     }
  38.  
  39.     public StudentConsultationForm() {
  40.         // Initialize form data
  41.         formData = new HashMap<>();
  42.  
  43.         // Set up the frame
  44.         setTitle("Student Consultation Form");
  45.         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  46.         setSize(900, 700);
  47.         setLocationRelativeTo(null);
  48.  
  49.         // Create the main panel
  50.         JPanel mainPanel = new JPanel();
  51.         mainPanel.setLayout(new BorderLayout());
  52.         mainPanel.setBackground(new Color(240, 240, 240));
  53.  
  54.         // Add the form components
  55.         JPanel formPanel = createFormPanel();
  56.         mainPanel.add(formPanel, BorderLayout.CENTER);
  57.  
  58.         // Add the header
  59.         JPanel headerPanel = createHeaderPanel();
  60.         mainPanel.add(headerPanel, BorderLayout.NORTH);
  61.  
  62.         // Add the main panel to the frame
  63.         setContentPane(mainPanel);
  64.     }
  65.  
  66.     private JPanel createHeaderPanel() {
  67.         JPanel panel = new JPanel();
  68.         panel.setBackground(new Color(30, 144, 255));
  69.         panel.setLayout(new BorderLayout());
  70.         panel.setBorder(new EmptyBorder(10, 0, 10, 0));
  71.  
  72.         JLabel titleLabel = new JLabel("Students Consultation Form", JLabel.CENTER);
  73.         titleLabel.setFont(new Font("Arial", Font.BOLD, 20));
  74.         titleLabel.setForeground(Color.WHITE);
  75.  
  76.         panel.add(titleLabel, BorderLayout.CENTER);
  77.  
  78.         return panel;
  79.     }
  80.  
  81.     private JPanel createFormPanel() {
  82.         JPanel panel = new JPanel();
  83.         panel.setBackground(Color.WHITE);
  84.         panel.setBorder(new EmptyBorder(20, 20, 20, 20));
  85.         panel.setLayout(new MigLayout("fillx", "[grow]", "[]10[]10[]"));
  86.  
  87.         // Add Basic Information Section
  88.         panel.add(createBasicInfoSection(), "span, grow, wrap");
  89.  
  90.         // Add the main content with two columns
  91.         JPanel mainContentPanel = new JPanel(new MigLayout("fillx", "[50%][50%]", "[]"));
  92.         mainContentPanel.setBackground(Color.WHITE);
  93.  
  94.         // Left column
  95.         JPanel leftPanel = new JPanel(new MigLayout("fillx", "[grow]", "[]10[]10[]"));
  96.         leftPanel.setBackground(Color.WHITE);
  97.         leftPanel.add(createConsultationReasonsSection(), "span, grow, wrap");
  98.         leftPanel.add(createStudentConcernSection(), "span, grow, wrap");
  99.         leftPanel.add(createStudentStatementSection(), "span, grow, wrap");
  100.  
  101.         // Right column
  102.         JPanel rightPanel = new JPanel(new MigLayout("fillx", "[grow]", "[]10[]10[]"));
  103.         rightPanel.setBackground(Color.WHITE);
  104.         rightPanel.add(createGuidancePlanSection(), "span, grow, wrap");
  105.         rightPanel.add(createFollowUpSection(), "span, grow, wrap");
  106.         rightPanel.add(createSignaturesSection(), "span, grow, wrap");
  107.  
  108.         mainContentPanel.add(leftPanel, "grow");
  109.         mainContentPanel.add(rightPanel, "grow");
  110.  
  111.         panel.add(mainContentPanel, "span, grow, wrap");
  112.  
  113.         // Add Form Actions
  114.         panel.add(createActionButtonsPanel(), "span, grow, right");
  115.  
  116.         return panel;
  117.     }
  118.  
  119.     private JPanel createBasicInfoSection() {
  120.         JPanel panel = new JPanel();
  121.         panel.setLayout(new MigLayout("fillx", "[grow]", "[]5[]"));
  122.         panel.setBackground(Color.WHITE);
  123.  
  124.         // Section Title
  125.         JLabel titleLabel = new JLabel("Basic Information", JLabel.CENTER);
  126.         titleLabel.setFont(new Font("Arial", Font.BOLD, 14));
  127.         titleLabel.setBackground(new Color(230, 230, 230));
  128.         titleLabel.setOpaque(true);
  129.         titleLabel.setBorder(new EmptyBorder(5, 0, 5, 0));
  130.         panel.add(titleLabel, "span, grow, wrap");
  131.  
  132.         // First row
  133.         studentNameField = createTextField();
  134.         gradeField = createTextField();
  135.         schoolField = createTextField();
  136.         consultantNameField = createTextField();
  137.  
  138.         panel.add(createLabeledComponent("Student Name:", studentNameField), "cell 0 1, growx");
  139.         panel.add(createLabeledComponent("Grade Level/Section:", gradeField), "cell 1 1, growx");
  140.         panel.add(createLabeledComponent("School:", schoolField), "cell 2 1, growx");
  141.         panel.add(createLabeledComponent("Consultant Name:", consultantNameField), "cell 3 1, growx");
  142.  
  143.         // Second row
  144.         SpinnerDateModel dateTimeModel = new SpinnerDateModel();
  145.         dateTimeSpinner = new JSpinner(dateTimeModel);
  146.         JSpinner.DateEditor dateTimeEditor = new JSpinner.DateEditor(dateTimeSpinner, "yyyy-MM-dd HH:mm");
  147.         dateTimeSpinner.setEditor(dateTimeEditor);
  148.  
  149.         SpinnerDateModel dateConModel = new SpinnerDateModel();
  150.         dateConSpinner = new JSpinner(dateConModel);
  151.         JSpinner.DateEditor dateConEditor = new JSpinner.DateEditor(dateConSpinner, "yyyy-MM-dd");
  152.         dateConSpinner.setEditor(dateConEditor);
  153.  
  154.         witnessesField = createTextField();
  155.  
  156.         panel.add(createLabeledComponent("Incident Date/Time:", dateTimeSpinner), "cell 0 2, growx");
  157.         panel.add(createLabeledComponent("Date of Counseling:", dateConSpinner), "cell 1 2, growx");
  158.         panel.add(createLabeledComponent("Names of Witnesses:", witnessesField), "cell 2 2, growx");
  159.  
  160.         return panel;
  161.     }
  162.  
  163.     private JPanel createConsultationReasonsSection() {
  164.         JPanel panel = new JPanel();
  165.         panel.setLayout(new MigLayout("fillx", "[grow]", "[]5[]"));
  166.         panel.setBackground(Color.WHITE);
  167.  
  168.         // Section Title
  169.         JLabel titleLabel = new JLabel("Reason for Consultation", JLabel.CENTER);
  170.         titleLabel.setFont(new Font("Arial", Font.BOLD, 14));
  171.         titleLabel.setBackground(new Color(230, 230, 230));
  172.         titleLabel.setOpaque(true);
  173.         titleLabel.setBorder(new EmptyBorder(5, 0, 5, 0));
  174.         panel.add(titleLabel, "span, grow, wrap");
  175.  
  176.         // Checkboxes in a grid
  177.         frequentAbsencesBox = new JCheckBox("Frequent Absences/Tardiness");
  178.         bullyingOrFightingBox = new JCheckBox("Bullying/Fighting");
  179.         academicPerfBox = new JCheckBox("Academic Performance");
  180.         failedAssignmentsBox = new JCheckBox("Failed to Submit Assignments");
  181.         misbehaviorBox = new JCheckBox("Misbehavior in Class");
  182.         schoolRuleViolationBox = new JCheckBox("School Rule Violation");
  183.         disrespectfulBox = new JCheckBox("Disrespectful Behavior");
  184.         othersBox = new JCheckBox("Other");
  185.  
  186.         panel.add(frequentAbsencesBox, "cell 0 1");
  187.         panel.add(misbehaviorBox, "cell 1 1");
  188.         panel.add(academicPerfBox, "cell 0 2");
  189.         panel.add(schoolRuleViolationBox, "cell 1 2");
  190.         panel.add(failedAssignmentsBox, "cell 0 3");
  191.         panel.add(othersBox, "cell 1 3");
  192.         panel.add(disrespectfulBox, "cell 0 4");
  193.         panel.add(bullyingOrFightingBox, "cell 1 4");
  194.  
  195.         return panel;
  196.     }
  197.  
  198.     private JPanel createStudentConcernSection() {
  199.         JPanel panel = new JPanel();
  200.         panel.setLayout(new MigLayout("fillx", "[grow]", "[]5[]"));
  201.         panel.setBackground(Color.WHITE);
  202.  
  203.         JLabel label = new JLabel("Description of Student Concern:");
  204.         label.setFont(new Font("Arial", Font.BOLD, 12));
  205.  
  206.         descStudentConcernArea = new JTextArea();
  207.         descStudentConcernArea.setRows(5);
  208.         descStudentConcernArea.setLineWrap(true);
  209.         descStudentConcernArea.setWrapStyleWord(true);
  210.  
  211.         JScrollPane scrollPane = new JScrollPane(descStudentConcernArea);
  212.         scrollPane.setBorder(BorderFactory.createLineBorder(Color.LIGHT_GRAY));
  213.  
  214.         panel.add(label, "wrap");
  215.         panel.add(scrollPane, "span, grow, h 100");
  216.  
  217.         return panel;
  218.     }
  219.  
  220.     private JPanel createStudentStatementSection() {
  221.         JPanel panel = new JPanel();
  222.         panel.setLayout(new MigLayout("fillx", "[grow]", "[]5[]"));
  223.         panel.setBackground(Color.WHITE);
  224.  
  225.         JLabel label = new JLabel("Student Statement:");
  226.         label.setFont(new Font("Arial", Font.BOLD, 12));
  227.  
  228.         studentStatementArea = new JTextArea();
  229.         studentStatementArea.setRows(5);
  230.         studentStatementArea.setLineWrap(true);
  231.         studentStatementArea.setWrapStyleWord(true);
  232.  
  233.         JScrollPane scrollPane = new JScrollPane(studentStatementArea);
  234.         scrollPane.setBorder(BorderFactory.createLineBorder(Color.LIGHT_GRAY));
  235.  
  236.         panel.add(label, "wrap");
  237.         panel.add(scrollPane, "span, grow, h 100");
  238.  
  239.         return panel;
  240.     }
  241.  
  242.     private JPanel createGuidancePlanSection() {
  243.         JPanel panel = new JPanel();
  244.         panel.setLayout(new MigLayout("fillx", "[grow]", "[]5[]"));
  245.         panel.setBackground(Color.WHITE);
  246.  
  247.         JLabel label = new JLabel("Summary of Guidance Plan or Action Taken:");
  248.         label.setFont(new Font("Arial", Font.BOLD, 12));
  249.  
  250.         summaryOfGuidancePlanArea = new JTextArea();
  251.         summaryOfGuidancePlanArea.setRows(5);
  252.         summaryOfGuidancePlanArea.setLineWrap(true);
  253.         summaryOfGuidancePlanArea.setWrapStyleWord(true);
  254.  
  255.         JScrollPane scrollPane = new JScrollPane(summaryOfGuidancePlanArea);
  256.         scrollPane.setBorder(BorderFactory.createLineBorder(Color.LIGHT_GRAY));
  257.  
  258.         panel.add(label, "wrap");
  259.         panel.add(scrollPane, "span, grow, h 100");
  260.  
  261.         return panel;
  262.     }
  263.  
  264.     private JPanel createFollowUpSection() {
  265.         JPanel panel = new JPanel();
  266.         panel.setLayout(new MigLayout("fillx", "[grow]", "[]5[]"));
  267.         panel.setBackground(Color.WHITE);
  268.  
  269.         JLabel label = new JLabel("Follow-up Date:");
  270.         label.setFont(new Font("Arial", Font.BOLD, 12));
  271.  
  272.         SpinnerDateModel followUpModel = new SpinnerDateModel();
  273.         followUpDateSpinner = new JSpinner(followUpModel);
  274.         JSpinner.DateEditor followUpEditor = new JSpinner.DateEditor(followUpDateSpinner, "yyyy-MM-dd");
  275.         followUpDateSpinner.setEditor(followUpEditor);
  276.  
  277.         panel.add(label, "wrap");
  278.         panel.add(followUpDateSpinner, "span, grow");
  279.  
  280.         return panel;
  281.     }
  282.  
  283.     private JPanel createSignaturesSection() {
  284.         JPanel panel = new JPanel();
  285.         panel.setLayout(new MigLayout("fillx", "[grow]", "[]5[]5[]"));
  286.         panel.setBackground(Color.WHITE);
  287.  
  288.         // Section Title
  289.         JLabel titleLabel = new JLabel("Signatures", JLabel.CENTER);
  290.         titleLabel.setFont(new Font("Arial", Font.BOLD, 14));
  291.         titleLabel.setBackground(new Color(230, 230, 230));
  292.         titleLabel.setOpaque(true);
  293.         titleLabel.setBorder(new EmptyBorder(5, 0, 5, 0));
  294.         panel.add(titleLabel, "span, grow, wrap");
  295.  
  296.         // First row
  297.         SpinnerDateModel dateStudentModel = new SpinnerDateModel();
  298.         dateStudentSpinner = new JSpinner(dateStudentModel);
  299.         JSpinner.DateEditor dateStudentEditor = new JSpinner.DateEditor(dateStudentSpinner, "yyyy-MM-dd");
  300.         dateStudentSpinner.setEditor(dateStudentEditor);
  301.  
  302.         SpinnerDateModel dateConSignModel = new SpinnerDateModel();
  303.         JSpinner dateConSignSpinner = new JSpinner(dateConSignModel);
  304.         JSpinner.DateEditor dateConSignEditor = new JSpinner.DateEditor(dateConSignSpinner, "yyyy-MM-dd");
  305.         dateConSignSpinner.setEditor(dateConSignEditor);
  306.  
  307.         panel.add(createLabeledComponent("Student Signature Date:", dateStudentSpinner), "cell 0 1, growx");
  308.         panel.add(createLabeledComponent("Consultant Signature Date:", dateConSignSpinner), "cell 1 1, growx");
  309.  
  310.         // Second row
  311.         SpinnerDateModel dateGuardianModel = new SpinnerDateModel();
  312.         dateGuardianSpinner = new JSpinner(dateGuardianModel);
  313.         JSpinner.DateEditor dateGuardianEditor = new JSpinner.DateEditor(dateGuardianSpinner, "yyyy-MM-dd");
  314.         dateGuardianSpinner.setEditor(dateGuardianEditor);
  315.  
  316.         receivedField = createTextField();
  317.  
  318.         SpinnerDateModel dateAdminModel = new SpinnerDateModel();
  319.         dateAdminSpinner = new JSpinner(dateAdminModel);
  320.         JSpinner.DateEditor dateAdminEditor = new JSpinner.DateEditor(dateAdminSpinner, "yyyy-MM-dd");
  321.         dateAdminSpinner.setEditor(dateAdminEditor);
  322.  
  323.         panel.add(createLabeledComponent("Parent/Guardian Date:", dateGuardianSpinner), "cell 0 2, growx");
  324.         panel.add(createLabeledComponent("School Administrator:", receivedField), "cell 1 2, growx");
  325.         panel.add(createLabeledComponent("Administrator Date:", dateAdminSpinner), "cell 2 2, growx");
  326.  
  327.         return panel;
  328.     }
  329.  
  330.     private JPanel createActionButtonsPanel() {
  331.         JPanel panel = new JPanel();
  332.         panel.setLayout(new FlowLayout(FlowLayout.RIGHT));
  333.         panel.setBackground(Color.WHITE);
  334.  
  335.         JButton resetButton = new JButton("Reset");
  336.         resetButton.setBackground(new Color(200, 200, 200));
  337.         resetButton.setForeground(Color.BLACK);
  338.         resetButton.setFocusPainted(false);
  339.         resetButton.addActionListener(new ActionListener() {
  340.             @Override
  341.             public void actionPerformed(ActionEvent e) {
  342.                 resetForm();
  343.             }
  344.         });
  345.  
  346.         JButton submitButton = new JButton("Submit");
  347.         submitButton.setBackground(new Color(30, 144, 255));
  348.         submitButton.setForeground(Color.WHITE);
  349.         submitButton.setFocusPainted(false);
  350.         submitButton.addActionListener(new ActionListener() {
  351.             @Override
  352.             public void actionPerformed(ActionEvent e) {
  353.                 submitForm();
  354.             }
  355.         });
  356.  
  357.         panel.add(resetButton);
  358.         panel.add(Box.createHorizontalStrut(10));
  359.         panel.add(submitButton);
  360.  
  361.         return panel;
  362.     }
  363.  
  364.     private JTextField createTextField() {
  365.         JTextField textField = new JTextField();
  366.         textField.setBorder(BorderFactory.createCompoundBorder(
  367.                 BorderFactory.createLineBorder(Color.LIGHT_GRAY),
  368.                 BorderFactory.createEmptyBorder(5, 5, 5, 5)));
  369.         return textField;
  370.     }
  371.  
  372.     private JPanel createLabeledComponent(String labelText, JComponent component) {
  373.         JPanel panel = new JPanel();
  374.         panel.setLayout(new MigLayout("fillx, insets 0", "[grow]", "[]2[]"));
  375.         panel.setBackground(Color.WHITE);
  376.  
  377.         JLabel label = new JLabel(labelText);
  378.         label.setFont(new Font("Arial", Font.PLAIN, 12));
  379.  
  380.         panel.add(label, "wrap");
  381.         panel.add(component, "growx");
  382.  
  383.         return panel;
  384.     }
  385.  
  386.     private void resetForm() {
  387.         // Clear all text fields
  388.         studentNameField.setText("");
  389.         gradeField.setText("");
  390.         schoolField.setText("");
  391.         consultantNameField.setText("");
  392.         witnessesField.setText("");
  393.         receivedField.setText("");
  394.  
  395.         // Clear all text areas
  396.         descStudentConcernArea.setText("");
  397.         summaryOfGuidancePlanArea.setText("");
  398.         studentStatementArea.setText("");
  399.  
  400.         // Uncheck all checkboxes
  401.         frequentAbsencesBox.setSelected(false);
  402.         bullyingOrFightingBox.setSelected(false);
  403.         academicPerfBox.setSelected(false);
  404.         failedAssignmentsBox.setSelected(false);
  405.         misbehaviorBox.setSelected(false);
  406.         schoolRuleViolationBox.setSelected(false);
  407.         disrespectfulBox.setSelected(false);
  408.         othersBox.setSelected(false);
  409.  
  410.         // Reset all date spinners to current date
  411.         Date currentDate = new Date();
  412.         dateTimeSpinner.setValue(currentDate);
  413.         dateConSpinner.setValue(currentDate);
  414.         followUpDateSpinner.setValue(currentDate);
  415.         dateStudentSpinner.setValue(currentDate);
  416.         dateGuardianSpinner.setValue(currentDate);
  417.         dateAdminSpinner.setValue(currentDate);
  418.  
  419.         JOptionPane.showMessageDialog(this, "Form has been reset", "Reset", JOptionPane.INFORMATION_MESSAGE);
  420.     }
  421.  
  422.     private void submitForm() {
  423.         // Collect form data
  424.         collectFormData();
  425.  
  426.         // Print to console (for testing)
  427.         System.out.println("Form Data Submitted:");
  428.         for (Map.Entry<String, Object> entry : formData.entrySet()) {
  429.             System.out.println(entry.getKey() + ": " + entry.getValue());
  430.         }
  431.  
  432.         // Show success message
  433.         JOptionPane.showMessageDialog(this, "Form submitted successfully!", "Success", JOptionPane.INFORMATION_MESSAGE);
  434.     }
  435.  
  436.     private void collectFormData() {
  437.         SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
  438.         SimpleDateFormat dateTimeFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  439.  
  440.         formData.put("studentName", studentNameField.getText());
  441.         formData.put("grade", gradeField.getText());
  442.         formData.put("school", schoolField.getText());
  443.         formData.put("conName", consultantNameField.getText());
  444.         formData.put("dateTime", dateTimeFormat.format(dateTimeSpinner.getValue()));
  445.         formData.put("dateCon", dateFormat.format(dateConSpinner.getValue()));
  446.         formData.put("witnesses", witnessesField.getText());
  447.  
  448.         formData.put("frequentAbsences", frequentAbsencesBox.isSelected() ? "X" : "");
  449.         formData.put("bullyingOrFighting", bullyingOrFightingBox.isSelected() ? "X" : "");
  450.         formData.put("academicPerf", academicPerfBox.isSelected() ? "X" : "");
  451.         formData.put("failedAssignments", failedAssignmentsBox.isSelected() ? "X" : "");
  452.         formData.put("misbehavior", misbehaviorBox.isSelected() ? "X" : "");
  453.         formData.put("schoolRuleViolation", schoolRuleViolationBox.isSelected() ? "X" : "");
  454.         formData.put("disrespectful", disrespectfulBox.isSelected() ? "X" : "");
  455.         formData.put("others", othersBox.isSelected() ? "X" : "");
  456.  
  457.         formData.put("descStudentConcern", descStudentConcernArea.getText());
  458.         formData.put("summaryOfGuidancePlan", summaryOfGuidancePlanArea.getText());
  459.         formData.put("studentStatement", studentStatementArea.getText());
  460.  
  461.         formData.put("followUpDate", dateFormat.format(followUpDateSpinner.getValue()));
  462.         formData.put("dateStudent", dateFormat.format(dateStudentSpinner.getValue()));
  463.         formData.put("dateGuardian", dateFormat.format(dateGuardianSpinner.getValue()));
  464.         formData.put("received", receivedField.getText());
  465.         formData.put("dateAdmin", dateFormat.format(dateAdminSpinner.getValue()));
  466.     }
  467. }
  468.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement