From: Arnaud Giersch Date: Tue, 14 Oct 2014 13:19:02 +0000 (+0200) Subject: Fix window closing. X-Git-Tag: extracted~20 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/graphlib_java.git/commitdiff_plain/9f587f17250c2bfe9812fa05e8697a2c45531dbc Fix window closing. --- diff --git a/DrawingWindow.java b/DrawingWindow.java index 4172235..670c854 100644 --- a/DrawingWindow.java +++ b/DrawingWindow.java @@ -621,6 +621,8 @@ public class DrawingWindow { colorMap = Collections.unmodifiableMap(m); } + private static int instances = 0; + private final String title; // window's title private JFrame frame; // the frame (window) private DWPanel panel; // the panel showing the image @@ -630,6 +632,7 @@ public class DrawingWindow { // To be run on the Event Dispatching Thread void createGUI() { + DrawingWindow.instances++; panel = new DWPanel(this); frame = new JFrame(title); frame.add(panel); @@ -643,6 +646,13 @@ public class DrawingWindow { } } }); + frame.addWindowListener(new WindowAdapter(){ + public void windowClosed(WindowEvent e) { + // System.err.println("CLOSED: " + DrawingWindow.instances); + if (--DrawingWindow.instances == 0) + System.exit(0); + } + }); frame.setLocationByPlatform(true); frame.setVisible(true); }