File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 EJB 3 in Action this week in the EJB and other Java EE Technologies 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
Author

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

Joined: Jul 11, 2001
Posts: 15286
    
    6

Pass the user into the RegistrationConfirmation constructor.


GenRocket - A Test Data Generation Platform
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: http://aspose.com/file-tools
 
subject: How to get a Username on the next page
 
Similar Threads
Swing event handling for a JButton?
help I am having trouble getting the field to fill in
aligning label and fields in Swing
displaying constantly generated text in JTextArea
remove lines in a JtextArea