Closing one window and opening another

Discussion in 'Java' started by zilvar@gmail.com, Aug 30, 2006.

  1. Guest

    Using Netbeans 5.0, I'm trying to teach myself some Java more
    complicated than System.out.println("Hello World.");

    I'd like some help figuring out the best way to build a login-style
    screen. It seems that I could create a main class and the two forms.
    My main could call LoginScreen, which listens for a button press, hides
    itself on command ... and this is where I get iffy. I doubt action
    listeners can return a value, so I think I need to implement a personal
    'yo, successful login' event and wrap that around login in a try/catch
    block, which would catch the event and ask the 2nd window to show
    itself.

    Is that a reasonable implementation of the idea, and if not, some
    pointers to whatever I'm missing would be much appreciated. :)

    Thanks
     
    , Aug 30, 2006
    #1
    1. Advertising

  2. Oliver Wong Guest

    <> wrote in message
    news:...
    > Using Netbeans 5.0, I'm trying to teach myself some Java more
    > complicated than System.out.println("Hello World.");
    >
    > I'd like some help figuring out the best way to build a login-style
    > screen. It seems that I could create a main class and the two forms.
    > My main could call LoginScreen, which listens for a button press, hides
    > itself on command ... and this is where I get iffy. I doubt action
    > listeners can return a value, so I think I need to implement a personal
    > 'yo, successful login' event and wrap that around login in a try/catch
    > block, which would catch the event and ask the 2nd window to show
    > itself.
    >
    > Is that a reasonable implementation of the idea, and if not, some
    > pointers to whatever I'm missing would be much appreciated. :)


    Consider using a modal Dialog instead of a Window. A modal Dialog will
    not allow execution to continue the the Dialog is closed. Once it has
    closed, your code can query about the nature of the closing (did the user
    click on "ok" or "cancel"? What are the contents of any textfields on that
    Dialog? etc.)

    - Oliver
     
    Oliver Wong, Aug 30, 2006
    #2
    1. Advertising

  3. VisionSet Guest

    <> wrote in message
    news:...
    > Using Netbeans 5.0, I'm trying to teach myself some Java more
    > complicated than System.out.println("Hello World.");
    >
    > I'd like some help figuring out the best way to build a login-style
    > screen. It seems that I could create a main class and the two forms.
    > My main could call LoginScreen, which listens for a button press, hides
    > itself on command ... and this is where I get iffy. I doubt action
    > listeners can return a value, so I think I need to implement a personal
    > 'yo, successful login' event and wrap that around login in a try/catch
    > block, which would catch the event and ask the 2nd window to show
    > itself.
    >
    > Is that a reasonable implementation of the idea, and if not, some
    > pointers to whatever I'm missing would be much appreciated. :)
    >


    I've done this with a CardLayout presenting the login screen first.
    The Login component is a separate class to which I can add a listener for
    successful login. This keeps the login screen responsible for displaying
    bad login information. You only need a regular ActionListener.
    Of course you should have model classes that decouple presentation from
    logic and that do the actual validation... If this is anymore than a toy
    app.
    Oh and remember exception handling is for exceptional conditions.

    --
    Mike W
     
    VisionSet, Aug 30, 2006
    #3
  4. Ralf Seitner Guest

    schrieb:
    > Using Netbeans 5.0, I'm trying to teach myself some Java more
    > complicated than System.out.println("Hello World.");
    >
    > I'd like some help figuring out the best way to build a login-style
    > screen. It seems that I could create a main class and the two forms.
    > My main could call LoginScreen, which listens for a button press, hides
    > itself on command ... and this is where I get iffy. I doubt action
    > listeners can return a value, so I think I need to implement a personal
    > 'yo, successful login' event and wrap that around login in a try/catch
    > block, which would catch the event and ask the 2nd window to show
    > itself.
    >
    > Is that a reasonable implementation of the idea, and if not, some
    > pointers to whatever I'm missing would be much appreciated. :)
    >
    > Thanks
    >

    Hi!
    I don't know what you want to do with the try/catch-block.
    The first thing which comes to my mind:
    I think you can use a method, which performs the login, and returns a
    boolean (means: returns whether the login was successful)

    You have a button, where an ActionListener listens on ActionEvents.
    So... when an action is performed check if login was successful and if
    so, close the first window/dialog/frame and open the next one.
    But maybe I totally misunderstood you...

    This could look like the following ...

    public boolean login(String userName, String passWord) {
    boolean loginSuccessful = false;
    // do something here to check if login is successful and
    // do some operations which have to be done if login
    // was successful - but only do them, if login is successful.
    // if successful set loginSucessful to true.
    return loginSuccessful;
    }

    and then in your ActionListener... (you can realize your implementation
    of the ActionListener as an inner class, so you can access on methods
    defined in that class...)
    public void actionPerformed(ActionEvent e) {
    boolean loginSuccessful;
    if (loginSuccessful) {
    loginScreen.setVisible(false);
    // probably even: loginScreen.dispose();
    JDialog dialogWhichFollowsOnSuccessfulLogin =
    createDialogWhichFollowsOnSuccessfulLogin()
    dialogWhichComesAfterLogin.setVisible(true);
    } else {
    // write a message and reset the password-field.
    }
    }
    private void createDialogWhichFollowsOnSuccessfulLogin {
    // create the dialog...
    }
    hth, bye, Ralf
     
    Ralf Seitner, Aug 30, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Patrick Olurotimi Ige

    Closing child window when opening a new Window

    Patrick Olurotimi Ige, Dec 14, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    451
    Patrick Olurotimi Ige
    Dec 14, 2004
  2. =?Utf-8?B?Vk1J?=

    Closing popup window when closing parent window?

    =?Utf-8?B?Vk1J?=, Feb 14, 2007, in forum: ASP .Net
    Replies:
    3
    Views:
    662
    Thomas Hansen
    Feb 15, 2007
  3. Jawahar Rajan
    Replies:
    2
    Views:
    155
  4. Eric B Venet
    Replies:
    0
    Views:
    103
    Eric B Venet
    Jul 31, 2003
  5. thomas
    Replies:
    0
    Views:
    237
    thomas
    Oct 23, 2003
Loading...

Share This Page