Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Restart login if a wrong password is writed. (Java Swing)

 
Toni Bullon
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I have some experience in Java, but very little in Swing.
I'm doing a GUI application using Java Swing and the first thing I do is that the user enter a password and depending on whether correct or not repeat the process or continue. To do this I have a frame for the Login and another for the rest of application.

The problem is going back to restart Login if you put the wrong password.

I'm trying with Listeners and DoWhile but I think it's not the way.

I have a main class that calls the Login. If the password is correct, the login window disappears and another of a new class appears. This more or less OK.

If the password is wrong I can't return to the main and re-create the Object Login. I do everything within ActionPerformed of the OK button, but this method will not let me return anything, then that's where I stay.

MAIN CLASS:


LOGIN CLASS:

I might be in the wrong way. I would appreciate advice, assistance or explanation of how you should do what I want.

If you need more information or details about what I want do not hesitate to ask.

Thank you very much. And sorry for my english.
 
Andrey Kozhanov
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would make login window modal dialog (please see how to make dialogs in Swing: http://download.oracle.com/javase/tutorial/uiswing/components/dialog.html). After that it's easy to get login result and show login again, if needed.
 
Darryl Burke
Bartender
Posts: 5126
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it's easy to get login result and show login again, if needed.


Far better to not close the login dialog until
  • the login is valid
  • the user clicked 'Cancel' or the [X] close button
  • a certain number of unsuccessful attempts are exceeded



  •  
    Toni Bullon
    Greenhorn
    Posts: 5
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thank you very much both.
    Andrey I guess I can do with showInputDialog. I didn't know Dialog supports inputs.
    Otherwise, I'll try to make a code like Darryl's code.


    Thack you.
     
    Rob Spoor
    Sheriff
    Pie
    Posts: 20531
    54
    Chrome Eclipse IDE Java Windows
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    In case the validation is more time consuming, a SwingWorker is probably a better idea. Disable the button, then start the SwingWorker. If that validates correctly you can dispose the dialog as Darryl has shown, otherwise re-enable the button and show an error.
     
    Toni Bullon
    Greenhorn
    Posts: 5
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    And something like this??
    This works fine. But, is it a good solution?. If the validation process takes a long time should also use a Swingworking? How should I put it?

     
    Rob Spoor
    Sheriff
    Pie
    Posts: 20531
    54
    Chrome Eclipse IDE Java Windows
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Perhaps instead of Void Boolean can be used for the return type of doInBackground, but I'm not quite sure if calling get() in done() would be a wise idea.
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic