I have already tried that, it works but it doesn't work for my application becouse
the dialog box asks for user name and password and it contains a Login Button, and checks weather the user name and password is correct or incorrect,
if it is correct it close the Dialog box and allows you to use the application, the dialog box is modal dialog box and block the whole application until you type the correct user name and password. if it's correct. it close the dialog box.
So, now if I add windowListener, even the username and password is correct. it close the dialog box and ends with closing the whole application which is nothing that I want.
I might be wrong with the use of Modal Dialog box as user name and password form which blocks the whole application.
if there is an alternative to make a username and password form which comes before the application starts as I couldn't find a way to do it. now the application starts and it call the modal dialog box. and when you click on X button the dialog box close and lets you use the application.
I tried (Redecorate = false) which removes the whole title bar in Dialog box. it is okay and kindly solved my problem. but it raise another problem. which is the Screen Keyboard.
my application has a screen key board for touch Screen computers. when you click on KeyBoard Button in Dialog box to open the keyboard to type user name and password. the modal dialog box blocks whole application including keyboard which is a separate dialog box.
Thanks for you suggestions. if you get the chance to read my long message and you could find a solution. Please let me know
Frankly speaking, I find this design horrible from the usability perspective. If the user inputs the wrong credentials, the ideal way is to provide a feedback to the user about it and let him provide the proper credentials all over again. If the application is going to terminate, just because I made a typo, then I am sure I wouldn't like the application.
Thanks for your suggestions, Indeed I have my problems as I am new in Java
I am not copying code from here and there. ofcourse I know what I am doing.
my problems I have less information about API and the Java Library
I know that windowListener does not close the application. the DialogBox window listener does ( JDialogBox1.dispose() ) and that is fine.
so, I thought, if the dialog box Dispose then the application should be closed, so I add windows listener when the dialog box dispose (System.exit(0))
the application lets the user to enter username/password three times. if he failed the application automatically get closed. that is fine and working
so if the users input is correct. again I need to dispose the dialog box. and this also close the application. I managed to solved the problem with disabling the title bar in Dialog box.
I have broken the long line in your code tags. Are you sure it is safe to use System.exit() at all?
posted 5 years ago
Well, I'm not a Java expert and I understand that there is some caution about System.exit(). In my case I have a login dialog called from the application (a Frame). The login has only an Ok button and no cancel button. The login is not really to the application, but to the database the application connects to. So, if I start the application and clicks Ok without filling in any credentials, the application starts without any db connection. Hence, If a user starts the application by accident or changes his/her mind about it, I want the default closing operation to be exit so the application doesn't start unnecessarily. Hide or dispose will not solve that. I could have had a cancel button too and solved the problem more easily, but in this case I wanted the default close to be to quit the application.
In my case I see no problems with it and it works as expected. Is there any problem I should expect?
posted 5 years ago
So if you use System.exit() you will close the running JVM immediately. Will that allow one to log off the database? Will the database log one off automatically? Is there a risk of connections being left open at the database end? If so you will gradually exhaust connectivity to the database and suffer a resource leak. You can probably recover the leak by turning it off and on again, but you probably don't want to. You might, by the way, have the same problems with EXIT_ON_CLOSE.
I think you will have to create a Listener or other code which closes the connections and disposes the GUI before terminating the JVM.
posted 5 years ago
In my case, If I close the login dialog using the default closing operation and thus System.exit() no db connection is ever created. But if I do the same with the application, after having logged in and acquired a db connection, the situations you describe might well happen. I haven't thought of that to be honest and thank you for the comments. I'll have to fix this!
Lasagna is spaghetti flvored cake. Just like this tiny ad: