/* GUI03.java CIS 160 David Klick 2011-09-24 Letting program run until last window closed */ import javax.swing.JFrame; import javax.swing.SwingUtilities; public class GUI03 { static int windows = 0; public GUI03() { SwingUtilities.invokeLater(new Runnable() { public void run() { createAndShowGUI(); } }); } private void createAndShowGUI() { windows++; JFrame fra = new JFrame("Window #" + windows); fra.setSize(300, 200); fra.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); fra.setVisible(true); } public void finalize() { windows--; if (windows == 0) System.exit(0); } public static void main(String[] args) { GUI03 app1 = new GUI03(); GUI03 app2 = new GUI03(); GUI03 app3 = new GUI03(); } }