Click here to Skip to main content
15,895,084 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all ,

Please can anyone tell me how to close current form and open new one.? I have a login form at the beginning and when it is successful i want to open a new form passing the id that the user used to login to the new form so how can i do this in java ?

Thanks in advance.!
Posted

1 solution

Hi.

This is not something easy to explain in a post, but I'll give it a shot.

You don't specify whether you're using Swing, AWT, SWT, or whatever. I'll try to explain it in some general way, I have only done some SWT.

You should have a model, which encapsulates the data that you want to pass around between the forms. For example, a "User" class. This class would contain the username, whether login was successful, and any data that you want to keep in it.

Your log-in form, say class LoginWindow, should have a getter for the User instance. Now, to pass the User instance to the second form, you could do it through it's constructor, a setter, or maybe you could make the User class a singleton (http://en.wikipedia.org/wiki/Singleton_pattern[^]).

There are many ways to achieve what you're after, I'm showing at least one.

Hope this helps you.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900