Reputation: 91
File is created using Project → New(Right Click) → JFrame Form
I set title as XYZ
and I am trying to dispose this frame using a button on the frame using XYZ.dispose()
;
But actually not working
Upvotes: 0
Views: 614
Reputation: 128
When you create a new JFrame
this way (the way you have mentioned), then frame.dispose()
will not work as non-static method can't be referenced from a static context.
As you are closing the main frame not any internal frame,
For particularly disposing that frame:
this.dispose();
You can also do the exiting if you want, get the job done via:
System.exit(0);
For specifically disposing that frame, rather add one more instruction to your closing function with the code instruction:
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
/*an import required for this--> import javax.swing.WindowConstants;*/
This closes the main frame (not the same as disposing of internal frames!).
Upvotes: 1