I want to create an application in a swing to which validation of user is performed by providing login form. My application program name is application.java I developed a Login form(Loginform.java) using swings . It worked successfully . when i access it using my application.java class It performs validation and then complete application is terminate. please give me suggestion by which validation is done and My application program not to be teminated.
-
Please, add snippets of your code to direct us. What form do you use to implement `Loginform.java` `JFrame` or `Dialog`? – Maxim Shoustin Oct 27 '12 at 06:53
-
I use JFrame for developing LoginForm.java – user1758401 Oct 27 '12 at 07:02
2 Answers
I suppose if you use Loginform.java as JFrame, bear in mind that on close login you kill all your program. Implement Login form as Dialog and all will work as you expected.
Just initiate your main frame application.java (set class name with uppercase), Show Login JDialog Box and on success set main JFrame visible.
JDialog examples: link
How to create Login Dialog box see here

- 77,483
- 27
- 203
- 225
-
-
1"*bear in mind that on close `login` you kill all your program."* Not necessarily, see David's answer. OTOH +1 for the mention of dialogs & links to a page with examples of using modal dialogs. – Andrew Thompson Oct 28 '12 at 04:55
This is most likely due to the fact in your LoginForm.java you have called setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); which will cause your Event Dispatch Thread and Initial thread to be killed.
Rather use something like:
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
On a side note, it is not considered good practice to use multiple JFrames:
You can have a look at the CardLayout which will allow you to flip between JPanels on a single JFrame. Or use a JDialog as your login screen which will initiate the main JFrame
- 1
- 1
- 36,155
- 13
- 81
- 138