Here is my code:
public static String currentStudent = "";
public void login() {
boolean studentLoggedOn = false;
Student student = new Student();
PC_Dialog dialog = new PC_Dialog("Enter Login Information", "Student ID, Password-", "OK");
dialog.choice();
String studentID = dialog.getField(1);
String password = dialog.getField(2);
student = (Student) projectSystem.studentFile.retrieve(studentID);
if (studentID != null) {
if (password.equals(student.password)) {
currentStudent = studentID;
studentLoggedOn = true;
studentRun();
}
}
if (!studentLoggedOn) {
JOptionPane.showMessageDialog(null, "Either the user name or the password were incorrect");
login();
}
}
After all of that, the “currentStudent = studentID;” doesn’t seem to have any effect on the currentStudent String?
Your question is incomplete, but if I had to guess, I’d say you have a reference to currentStudent somewhere else in your code. Since strings are not mutable and the assignment operator also does not mutate objects, this reference would not change.
For example:
Will output
Try reading up on Java references and string assignment.
Per the question author’s request here’s an example that accomplishes what I think he wants.
And use the Session class as follows.