Closing JFrame(java created Window) - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Closing JFrame(java created Window)

Danish KamranDanish Kamran Posts: 31Member
Hi,
if we craete a window in java then we will write following code snippet
JFrame f = new JFrame("some Name"); , andt then
..........
......
....
..
At last to close the window through default operation i.e if the user of window click on cross(x) box at the to right corner of window then,
f.setDefaultCloseOperation(f.EXIT_ON_CLOSE);
Now , [b]My Question [/b]is
How to close this window programatically i.e through some check or condition Likewise if we want to close the whole programe we simply wirte
System.exit(0); and the program terminates automatically i want to terminate the JFrame throgh this Method.
Thanks

Comments

  • zibadianzibadian Posts: 6,349Member
    : Hi,
    : if we craete a window in java then we will write following code
    : snippet
    : JFrame f = new JFrame("some Name"); , andt then
    : ..........
    : ......
    : ....
    : ..
    : At last to close the window through default operation i.e if the
    : user of window click on cross(x) box at the to right corner of
    : window then,
    : f.setDefaultCloseOperation(f.EXIT_ON_CLOSE);
    : Now , [b]My Question [/b]is
    : How to close this window programatically i.e through some check or
    : condition Likewise if we want to close the whole programe we simply
    : wirte
    : System.exit(0); and the program terminates automatically i want to
    : terminate the JFrame throgh this Method.
    : Thanks
    :
    You can close and destroy a window by calling Displose(). If you only want to close the window, but use it later, it is best to set the visibility to false.
  • Gorge7777Gorge7777 Posts: 1Member
    : : Hi,
    : : if we craete a window in java then we will write following code
    : : snippet
    : : JFrame f = new JFrame("some Name"); , andt then
    : : ..........
    : : ......
    : : ....
    : : ..
    : : At last to close the window through default operation i.e if the
    : : user of window click on cross(x) box at the to right corner of
    : : window then,
    : : f.setDefaultCloseOperation(f.EXIT_ON_CLOSE);
    : : Now , [b]My Question [/b]is
    : : How to close this window programatically i.e through some check or
    : : condition Likewise if we want to close the whole programe we simply
    : : wirte
    : : System.exit(0); and the program terminates automatically i want to
    : : terminate the JFrame throgh this Method.
    : : Thanks
    : :
    : You can close and destroy a window by calling Displose(). If you
    : only want to close the window, but use it later, it is best to set
    : the visibility to false.

    If you call
    processWindowEvent( new WindowEvent( me, WindowEvent.WINDOW_CLOSING) );
    the JFrame will behave as if the 'x' has been clicked.
    This method will notify all registered window listeners.
    This does not happen if dispose is called instead.
    This is useful if you have code set to execute when the window is closed by the user and you want the same code to execute when the window is closed by code.
    This method should not be called from within the window listener itself as it will cause a loop.

Sign In or Register to comment.