Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to get a Username on the next page

 
Sege Stephen
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys, this might seem easy enough, but I HAVEn't been able to get it to work.

I created a registerGUi class, where the User set his username and Id, password and other things. I then added the Listener to register button to get the username from the username field when register is clicked. Everything works fine and I can save the details to the database. However, I created another page which i called RegisterConfirmation, basically it has a text area that contains the message: Welcome "username", you have successfully registered.

to launch this Frame - RegisterConfirmation, I am creating a new object which I put in my actionlistener, but everytime I get a null value. Ofcourse coming from a Java web background, this is easy as all I have to do is put the Username in a session scope, but I am new to Swing, so it different the way I have to handle this.

I created a setter and getter for String user- which I assign the username, but it seems every time If I created a new obejct of RegisterConfirmation, and then set user to username, it runs the constructor of RegisterConfirmation before setting the value , but this time in the text area the result is null

code Register class





Registrationconfirmation class

 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if you follow the flow, it has to be null

line 10 of Register class
regconf = new RegistrationConfirmation();
which calls the constructor

and on line 20 of RegistrationConfirmation constructor
tx.setText("Congratulations " +getUser()...
where getUser() is null

user is not set (setUser) until line 11 of Register class,
i.e. after RegistrationConfirmation constructor returns

 
Sege Stephen
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Michael,

That is true, but the problem I have is that I cannot call setUser() method before creating a new instance RegistrationConfirmation , because I need an instance the class to call the setUser() method. So how do I go about it?

I still don't know the solution.
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pass the user into the RegistrationConfirmation constructor.
 
Sege Stephen
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Gregg, it is very easy.

But i spent hours on it .
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic