Better to use the public void dispose () method
vk.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent we) { vk.dispose();
AWT - heavyweight, i.e. its components use system resources .
Windows does not block. This means that after creating the code in the code, the code continues to run.
This means that your window probably goes beyond the scope immediately after creation, unless you explicitly saved the link to it somewhere else. The window is still on the screen at this point.
It also means that you need another way to get rid of it when you are done with it. Enter the Window dispose () method, which can be called from one of the Window listeners.
source share