What's new

Help Java GUI Project Student Info

Fersonlante

Addict
Established
Joined
Sep 1, 2022
Posts
74
Reaction
22
Points
64
Pa help po sana ako sa GUI Project ko na Student info huhu need ASAP. Thank youu
 
Sure, I'd be happy to help you with your GUI project on student information. Could you please provide more details about the requirements and any specific issues or questions you have? The more information you provide, the better I can assist you.
 
Sure, I'd be happy to help you with your GUI project on student information. Could you please provide more details about the requirements and any specific issues or questions you have? The more information you provide, the better I can assist you.
ano po after ko po mag mag input ng mga student info like example student ID, first name ,last name birthdate and I choose the course BSIT, meron po list of all courses and when I choose List of all BSIT students all the information po magdidisplay sa jtable

/*
* 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 StudentPackage;
import javax.swing.JOptionPane;
import com.toedter.calendar.JTextFieldDateEditor;
import javax.swing.table.DefaultTableModel;
/**
*
* @author ashle
*/
public class StudentInfo extends javax.swing.JFrame {

/**
* Creates new form StudentInfo
*/
public StudentInfo() {
initComponents();
}

private void addFilteredStudentsToTable(String course, boolean isRegular, DefaultTableModel model) {
// Replace this with your actual logic to fetch students based on the selected course and status
// For now, I'm adding sample data to demonstrate the concept
String[] sampleData = {"2021", "Ashley", "Casul", "September 29, 2023", "BSIT", "3", String.valueOf(isRegular)};
if (course.isEmpty() || sampleData[4].equals(course)) {
model.addRow(sampleData);
}
// Add rows to the model based on your data
}

/**
* Retrieves the selected course based on radio button selection.
*/
private String getSelectedCourse() {
if (rB1.isSelected()) {
return "BSIT";
} else if (rB2.isSelected()) {
return "BSCS";
} else if (rB3.isSelected()) {
return "BSEMC";
} else if (rB4.isSelected()) {
return "BSIS";
} else {
return "";
}
}

/**
* Updates the table based on the selected option.
*/
private void updateTable() {
DefaultTableModel model = (DefaultTableModel) jTable1.getModel();
model.setRowCount(0); // Clear the existing rows in the table

// Retrieve the selected option from listStudents combo box
String selectedOption = listStudents.getSelectedItem().toString();

// Add logic to update the table based on the selected option
if (selectedOption.equals("List of all students")) {
// Display all students
// You may need to replace this with your actual logic to fetch and display all students
// Use a method to filter students based on the selected course and regular/irregular status
addFilteredStudentsToTable(getSelectedCourse(), check.isSelected(), model);
} else if (selectedOption.equals("List of all BSIT students")) {
// Display BSIT students
// You may need to replace this with your actual logic to fetch and display BSIT students
addFilteredStudentsToTable("BSIT", false, model);
} else if (selectedOption.equals("List of all BSCS students")) {
// Display BSCS students
// You may need to replace this with your actual logic to fetch and display BSCS students
addFilteredStudentsToTable("BSCS", false, model);
} else if (selectedOption.equals("List of all BSEMC students")) {
// Display BSEMC students
// You may need to replace this with your actual logic to fetch and display BSEMC students
addFilteredStudentsToTable("BSEMC", false, model);
} else if (selectedOption.equals("List of all BSIS students")) {
// Display BSIS students
// You may need to replace this with your actual logic to fetch and display BSIS students
addFilteredStudentsToTable("BSIS", false, model);
} else if (selectedOption.equals("List of all Regular students")) {
// Display Regular students
// You may need to replace this with your actual logic to fetch and display Regular students
addFilteredStudentsToTable("", true, model);
} else if (selectedOption.equals("List of all Irregular students")) {
// Display Irregular students
// You may need to replace this with your actual logic to fetch and display Irregular students
addFilteredStudentsToTable("", false, model);
}
// Add similar conditions for other options
}

/**
* Clears the form.
*/
private void clearForm() {
studentID.setText("");
tF2.setText("");
tF3.setText("");
date.setDate(null);
buttonGroup1.clearSelection();
cB1.setSelectedIndex(0);
check.setSelected(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">
private void initComponents() {

buttonGroup1 = new javax.swing.ButtonGroup();
jPanel1 = new javax.swing.JPanel();
lB1 = new javax.swing.JLabel();
lB2 = new javax.swing.JLabel();
lB3 = new javax.swing.JLabel();
lB4 = new javax.swing.JLabel();
lB5 = new javax.swing.JLabel();
tF2 = new javax.swing.JTextField();
tF3 = new javax.swing.JTextField();
rB1 = new javax.swing.JRadioButton();
rB2 = new javax.swing.JRadioButton();
rB3 = new javax.swing.JRadioButton();
rB4 = new javax.swing.JRadioButton();
cB1 = new javax.swing.JComboBox<String>();
lB6 = new javax.swing.JLabel();
lB7 = new javax.swing.JLabel();
check = new javax.swing.JCheckBox();
add = new javax.swing.JButton();
clear = new javax.swing.JButton();
studentID = new javax.swing.JTextField();
jPanel2 = new javax.swing.JPanel();
listStudents = new javax.swing.JComboBox<String>();
jScrollPane2 = new javax.swing.JScrollPane();
jTable1 = new javax.swing.JTable();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Student Information");
setBackground(new java.awt.Color(153, 255, 255));

jPanel1.setBackground(new java.awt.Color(255, 255, 204));
jPanel1.setForeground(new java.awt.Color(255, 255, 255));

lB1.setText("Student ID");

lB2.setText("First Name");

lB3.setText("Last Name");

lB4.setText("Birthdate");

lB5.setText("Course");

buttonGroup1.add(rB1);
rB1.setText("BSIT");

buttonGroup1.add(rB2);
rB2.setText("BSCS");

buttonGroup1.add(rB3);
rB3.setText("BSEMC");

buttonGroup1.add(rB4);
rB4.setText("BSIS");

cB1.setModel(new javax.swing.DefaultComboBoxModel<String>(new String[] { "1", "2", "3", "4" }));

lB6.setText("Year Level");

lB7.setText("Regular Student");

add.setText("Add");
add.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
addActionPerformed(evt);
}
});

clear.setText("Clear");

studentID.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
studentIDActionPerformed(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(32, 32, 32)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(lB2)
.addComponent(lB3)
.addComponent(lB4)
.addComponent(lB5)
.addComponent(lB1)
.addComponent(lB6))
.addGap(45, 45, 45)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(cB1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(studentID, javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(rB1)
.addComponent(rB2))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(rB4)
.addComponent(rB3)))
.addComponent(tF3, javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(tF2, javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(0, 0, Short.MAX_VALUE)
.addComponent(clear)))
.addGap(156, 156, 156))))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(add, javax.swing.GroupLayout.PREFERRED_SIZE, 59, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
.addComponent(lB7)
.addGap(18, 18, 18)
.addComponent(check)))
.addContainerGap())))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(25, 25, 25)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lB1)
.addComponent(studentID, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lB2)
.addComponent(tF2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lB3)
.addComponent(tF3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(29, 29, 29)
.addComponent(lB4)
.addGap(24, 24, 24)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(lB5)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(rB1)
.addComponent(rB3)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(rB2)
.addComponent(rB4))
.addGap(28, 28, 28)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(cB1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(lB6))
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(check)
.addComponent(lB7))
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(add)
.addComponent(clear))
.addContainerGap(27, Short.MAX_VALUE))
);

jPanel2.setBackground(new java.awt.Color(204, 255, 204));

listStudents.setModel(new javax.swing.DefaultComboBoxModel<String>(new String[] { "List of all students", "List of all BSIT students", "List of all BSCS students", "List of all BSEMC students", "List of all BSIS students", "List of all Regular students", "List of all Irregular students" }));

jTable1.setBackground(new java.awt.Color(204, 204, 255));
jTable1.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {

},
new String [] {
"Student ID", "First Name", "Last Name", "Birthdate", "Course", "Year Level", "Regular "
}
));
jScrollPane2.setViewportView(jTable1);

javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
jPanel2.setLayout(jPanel2Layout);
jPanel2Layout.setHorizontalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 659, Short.MAX_VALUE)
.addGroup(jPanel2Layout.createSequentialGroup()
.addComponent(listStudents, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 0, Short.MAX_VALUE)))
.addContainerGap())
);
jPanel2Layout.setVerticalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addGap(62, 62, 62)
.addComponent(listStudents, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(35, 35, 35)
.addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(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()
.addContainerGap()
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 350, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);

pack();
setLocationRelativeTo(null);
}// </editor-fold>

private void studentIDActionPerformed(java.awt.event.ActionEvent evt) {
String studentId = studentID.getText();

if (!studentId.isEmpty() && studentId.matches("\\d{4}")) {
System.out.println("Student ID: " + studentId);
} else {
JOptionPane.showMessageDialog(this, "Please enter a valid 4-digit student ID.", "Invalid Student ID", JOptionPane.ERROR_MESSAGE);
studentID.setText("");
}
}

private void addActionPerformed(java.awt.event.ActionEvent evt) {
String studentId = studentID.getText();
String firstName = tF2.getText();
String lastName = tF3.getText();
String birthdate = ((JTextFieldDateEditor) date.getDateEditor()).getText();
String course = getSelectedCourse();
String yearLevel = cB1.getSelectedItem().toString();
boolean isRegular = check.isSelected();

String[] studentData = {studentId, firstName, lastName, birthdate, course, yearLevel, String.valueOf(isRegular)};

DefaultTableModel model = (DefaultTableModel) jTable1.getModel();
model.addRow(studentData);

clearForm();
}

/**
* @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 You do not have permission to view the full content of this post. Log in or register now.
*/
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(StudentInfo.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(StudentInfo.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(StudentInfo.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(StudentInfo.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 StudentInfo().setVisible(true);
}
});
}

// Variables declaration - do not modify
private javax.swing.JButton add;
private javax.swing.ButtonGroup buttonGroup1;
private javax.swing.JComboBox<String> cB1;
private javax.swing.JCheckBox check;
private javax.swing.JButton clear;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JTable jTable1;
private javax.swing.JLabel lB1;
private javax.swing.JLabel lB2;
private javax.swing.JLabel lB3;
private javax.swing.JLabel lB4;
private javax.swing.JLabel lB5;
private javax.swing.JLabel lB6;
private javax.swing.JLabel lB7;
private javax.swing.JComboBox<String> listStudents;
private javax.swing.JRadioButton rB1;
private javax.swing.JRadioButton rB2;
private javax.swing.JRadioButton rB3;
private javax.swing.JRadioButton rB4;
private javax.swing.JTextField studentID;
private javax.swing.JTextField tF2;
private javax.swing.JTextField tF3;
// End of variables declaration
}
 

Similar threads

Back
Top