I have a Jframe class that has a login and password fields. When loggin on, i have to display informations of the person that logged in, so i have to retrieve his login from the first Jframe to make a treatment in the other one.
Here is that i made, but the login returns NULL in the second jframe:
First Jframe (login and password fields):
private void button_connectActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
String x= loginField.getText();
String y= passwordField.getText();
AuthentificationDAO authDAO= new AuthentificationDAO();
boolean ok_login= authDAO.verify_login(x);
int pass= Integer.parseInt(y);
System.out.println("password retrieved"+pass);
boolean ok_pass=authDAO.verify_password(pass);
System.out.println("ok pass"+ok_pass);
if (ok_login & ok_pass)
{
System.out.println("Login found!");
Enseignant e= new Enseignant();
edu.app.persistence.Enseignant ens= new edu.app.persistence.Enseignant(x);
//ens.setLogin(x);
System.out.println("login SET:"+ens.getLogin());
e.setVisible(true);
this.setVisible(false);
}
else {
System.out.println("Login NOT found!");
JOptionPane.showMessageDialog(null, "Accourt NOT found. Please check your login or password.", "Check Login/Pass", 1);
}
Second Jframe that will display informations of that login:
private void mauvaisFieldFocusGained(java.awt.event.FocusEvent evt) {
edu.app.persistence.Enseignant ens= new edu.app.persistence.Enseignant();
String login=ens.getLogin();
System.out.println("LOGIN EST:"+login);
StatsDAO stats= new StatsDAO();
int id=stats.get_id_from_login(login);
System.out.println("ID="+id);
}
Any idea please of how solving that problem?
Thank you very much.
Unless
ens.loginisstatic, this code won’t work.You can use the
MVCpattern or you can just make your second frame class extendsJFrame, in order to add a login field to it..Sonething like :
I’ve used a sort of pseudocode but it should be clear enough