I am storing the data of a small form of a JFrame in a array. I compare the number that was entered in the form with the number that the user is looking for. But it shows only shows the result of the last student added, those that already add does not find them
private void btnAddActionPerformed(java.awt.event.ActionEvent evt) {
if(counter< studentList.length){
String code= txtcode.getText();
String name= txtname.getText();
String lastname= txtlastname.getText();
String rh = comborh.getSelectedItem().toString();
int age= Integer.parseInt(txtage.getText());
//the object is created
Student objStudent = new Student();
objStudent.setCode(code);
objStudent.setName(name);
objStudent.setLastname(lastname);
objStudent.setAge(age);
objStudent.setRH(rh);
studentList[counter] = objStudent;
counter++;
JOptionPane.showMessageDialog(this,"n° "+ counter+ " Students.");
}else{
JOptionPane.showMessageDialog(this,"Error","Error", JOptionPane.ERROR_MESSAGE);
}
}
the information is added without problem in the array
this is the condition
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
String code= txtcode.getText();
String name= txtname.getText();
String search= JOptionPane.showInputDialog(this,"search by code");
for (int i = 0; i<=studentList.length;i++){
if ((search).equals(code)){
JOptionPane.showMessageDialog(this,"code with the name of: "+name);
}
}
}