So I have made a 'Student' class which has some data members,and methods....What I want to do is get input from the user using a form and then initialize a student object using the values entered by the user. I used the following code but somehow every Student object has the same values as the last entered user input. Srry for bad English
//Declared in main class
Student1 stu = new Student1();
Student1[] Student1Array = new Student1[200];
int Mcounter =0;
//elsewhere in the program
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
int Admno = Integer.parseInt(admTF.getText());
String Name = name.getText();
int Standard = Integer.parseInt((String)(ClassCB.getSelectedItem());
String S = (String)SectionCB.getSelectedItem();
char Section = S.charAt(0);
String G = (String)GenderCB.getSelectedItem();
char Gender = G.charAt(0);
stu.CreateStudent(Admno,Name,Standard,Section,Gender);
Student1Array[Mcounter]=stu;
Mcounter++;
}
//Student class
public class Student1 {
int standard;
char section ;
void CreateStudent(int n,String s,int c,char sec,char g){
admissionNo=n;
name=s;
standard=c;
section = sec;
gender=g;
}
}
The jButton is called whenever the user makes their entry, I need to populate the Student1Array but can't.
