jdialog dispose not works properly

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sezanawa
    New Member
    • Sep 2007
    • 9

    #1

    jdialog dispose not works properly

    Hi Guys,

    I have a small application which i wrote in Java. There is a MainFrame extends jfram class. There is another class named LoginDialog extends JDialog.

    My MainFrame class have main method where i create object of my Dialog class before i do setVisible(true ) for MainFrame.

    I just want that Login Dialog appears first and if user get authentication from System then it show MainFrame window.

    LoginDialog appears and when i press ok login button i check authentication and then if its true, i set a localvariable true then setVisible(fals e) so that LoginDialog disappears. And now i check in Mainframe for the localvariable of LoginDialog either its true or false.

    During debugg mode it show true and then i also calls my MainFrame but during run mode it does not works.

    I dont knw whats wrong here.?? Can any body helps me??

    here is code.

    MainFrame Class code....
    [HTML]
    public static void main(String[] args) {

    MainFrame aWindow= new MainFrame ();
    Toolkit thekit=aWindow. getToolkit();
    Dimension winsize=thekit. getScreenSize() ;
    aWindow.setBoun ds(winsize.widt h/3,winsize.heigh t/4,winsize.width/3,winsize.heigh t/3);
    aWindow.setDefa ultCloseOperati on(EXIT_ON_CLOS E);
    aWindow.setLoca tionRelativeTo( null);
    aWindow.setMaxi mumSize(new java.awt.Dimens ion(400, 325));
    aWindow.setAlwa ysOnTop(true);

    aWindow.loginCh ecked = aWindow.login() ;
    //aWindow.setVisi ble(true);
    if(aWindow.logi n()){

    aWindow.setVisi ble(true);
    }

    else if(!aWindow.til lNotLoged ) {
    System.out.prin tln("Sorry");
    aWindow.dispose ();

    }


    }

    private boolean login() {

    LoginDlg login = new LoginDlg(this);
    if(LoginDlg.log gedIn){

    return true;
    }
    return false;

    }
    [/HTML]
    Code from LoginDialog class
    [HTML]
    public static boolean loggedIn = false;

    private void jLoginBtnMouseC licked(MouseEve nt evt) {
    System.out.prin tln("jLoginBtn. mouseClicked, event=" + evt);
    this.setLoggedI n(true);
    //this.dispose();
    this.setVisible (false);

    }


    public void setLoggedIn(boo lean loggedIn) {
    this.loggedIn = loggedIn;
    }

    [/HTML]

    is there any way it should work by disposing dialog but still have class data members. As much i know dispose only clear GUI Elements (Panel, buttons, frams etc) from Memory and all other class functions are still in hand. Atleast in .Net it works.

    I need your urgent help.

    Thanks
    best regards
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Why don't you simply add an ActionListener to that 'OK' button and close the
    JDialog from within that ActionListener' s actionPerformed method? Note that
    when you dispose a JDialog, the entire object stays intact, it just becomes
    invisible.

    kind regards,

    Jos

    Comment

    • sezanawa
      New Member
      • Sep 2007
      • 9

      #3
      Originally posted by JosAH
      Why don't you simply add an ActionListener to that 'OK' button and close the
      JDialog from within that ActionListener' s actionPerformed method? Note that
      when you dispose a JDialog, the entire object stays intact, it just becomes
      invisible.

      kind regards,

      Jos

      Thanks Man,

      I am actually using a GUI Plugin named Jigglo. I just used there provided Event. I did not understand when i debugg program it works prefect but when i run it, it does not work. I am using Eclipse as IDE.

      What could be a reason for this problem.???

      Ok i gonna try it with Action Performed.

      Best regards

      Comment

      • JosAH
        Recognized Expert MVP
        • Mar 2007
        • 11453

        #4
        Originally posted by sezanawa
        Ok i gonna try it with Action Performed.
        Yes you should; those MouseEvents are really low level events and you don't
        want to deal with those; you want to handle the 'semantic' or higher level events
        such as ActionEvents fired by e.g. buttons; the button took care of the low level
        event and offers you a higher level event (an ActionEvent). Use those instead.

        kind regards,

        Jos

        Comment

        Working...