• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
      Number of slices to send:
      Optional 'thank-you' note:
    • 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.
     
    Sheriff
    Posts: 22787
    131
    Eclipse IDE Spring Chrome Java Windows
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • 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
      Number of slices to send:
      Optional 'thank-you' note:
    • 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
    Posts: 22787
    131
    Eclipse IDE Spring Chrome Java Windows
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • 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.
     
    reply
      Bookmark Topic Watch Topic
    • New Topic