I want to close JFrame
with click on close button. The frame closed but Window
related class is still running.
How can I close the frame so that the whole class is stopped?
public class Game {
public Game2() throws InterruptedException, IOException {
new TimerDemo(30,2);
while (flag) {
play();
}
}
private void play() throws InterruptedException, IOException {
NewJFrame fr = new NewJFrame();
fr.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
fr.addWindowListener(new java.awt.event.WindowAdapter() {
@Override
public void windowClosing(java.awt.event.WindowEvent e) {
e.getWindow().dispose();
System.out.println("JFrame Closed!");
}
});
}
}
In TimerDemo(30,2)
, after 30 seconds, play()
must be stop.
How to destroy completely class without using System.exit(0)
?