aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Restart login if a wrong password is writed. (Java Swing) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Restart login if a wrong password is writed. (Java Swing)" Watch "Restart login if a wrong password is writed. (Java Swing)" New topic
Author

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

Toni Bullon
Greenhorn

Joined: Jun 09, 2011
Posts: 5
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

Joined: Mar 12, 2010
Posts: 79
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

Joined: May 03, 2008
Posts: 4547
    
    5

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




  • luck, db
    There are no new questions, but there may be new answers.
    Toni Bullon
    Greenhorn

    Joined: Jun 09, 2011
    Posts: 5
    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

    Joined: Oct 27, 2005
    Posts: 19697
        
      20

    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.


    SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
    How To Ask Questions How To Answer Questions
    Toni Bullon
    Greenhorn

    Joined: Jun 09, 2011
    Posts: 5
    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

    Joined: Oct 27, 2005
    Posts: 19697
        
      20

    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.
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Restart login if a wrong password is writed. (Java Swing)