This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes How to get a Username on the next page Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How to get a Username on the next page" Watch "How to get a Username on the next page" New topic

How to get a Username on the next page

Sege Stephen
Ranch Hand

Joined: Oct 06, 2007
Posts: 51
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

Joined: Jun 09, 2003
Posts: 4632
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

Joined: Oct 06, 2007
Posts: 51

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
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15302

Pass the user into the RegistrationConfirmation constructor.

GenRocket - Experts at Building Test Data
Sege Stephen
Ranch Hand

Joined: Oct 06, 2007
Posts: 51
Thanks Gregg, it is very easy.

But i spent hours on it .
I agree. Here's the link:
subject: How to get a Username on the next page
It's not a secret anymore!