you can use setDefaultCloseOperation()
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
if you don't want to do somethings before close your frame
if you must do somethings (e.g. save, change some properties) you must use Window Listener.
if you use dispose()
when you show frame again that frame will appear same as before you called dispose()
I think you should clear data in Object(s) by yourself before call dispose() or affter you show its again.
// try this code
// if you didn't uncomment line: textField = new JTextField();
// data in textField will not be clear
// uncomment line: textField = new JTextField();
// and try again, you will got new child with no data in textFiled
import javax.swing.*;
import java.awt.event.*;
public...
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.