רגע
יצרת Frame כן ? לא משנה אם ב-AWT או ב-SWING כרגע. בד"כ נהוג להוסיף WindowAdapter לקוד שיוצר את החלון כדי לטפל באירועים שקשורים לחלון עצמו. עם כל אירוע (EVENT) יש מתודה שמקושרת אליו, את זה אתה כבר יודע אני מניח. המתודה של סגירת חלון היא public void windowClosing. לדוגמא:
public static void main( String[] args) { JFrame frame = new JFrame(); // forgot the args for it, nevermind now WindowListener wl = new WindowAdapter() { public void windowClosing( WindowEvent e) { System.exit(0); } } frame.addWindowListener( wl); frame.pack(); frame.setVisible( true); }
זה בעיקרון הרעיון, כמובן שהקוד לא מושלם...