Search This Blog

Showing posts with label make. Show all posts
Showing posts with label make. Show all posts

What Does Modal and Modeless (Non Modal) Mean in Java

In java, the dialogue boxes in JOptionPane class are very popular. Now when we use dialogue boxes, whether it is message dialogue box, input dialogue or any other,  we may sometimes need to make the parent container (often JFrame or JWindow) not focusable. In another words, we may have to prevent a (parent) component taking input from the user while one of its member component is active. (You may have noticed that when error message boxes are displayed, you cannot click its parent window on many software until you dismiss it by clicking 'OK' or 'close'). Such a property of a member or child component, is called modality. In java, you can use JDialog with or without modality. A JDialog can be either modal or modeless.
A Modal dialog box is a dialog box that blocks input to some other top-level windows in the application. The modal dialog box captures the window focus until it is closed, usually in response to a button press.
A Modeless dialog box is a dialog box that does not block input to any other top level window while it is shown.
See following java code example:

How to Close or Exit a Java App When some Button is Clicked

To close a Java app, System.exit() can be used. This function can be used to close the app if an error occurs or no error is occurred. If no, error occurred, the argument  of the function should be 0. This method terminates the currently running Java Virtual Machine. The argument stands for status code; by convention, a nonzero status code indicates abnormal termination. If you are calling the System.exit() function without any errors (in normal case), just give the argument as zero. This method calls the exit method in class Runtime.