class MyFrame extends Frame { // constructor MyFrame() { setSize( 200,300 ); hookWindowClosing(); setVisible( true ); } // end constructor private void hookWindowClosing() { this.setDefaultCloseOperation ( JFrame.DO_NOTHING_ON_CLOSE ); // what happens when user closes the JFrame. WindowListener windowListener = new WindowAdapter() { // anonymous WindowAdapter class public void windowClosing ( WindowEvent w ) { rememberLocation( MyFrame.this.getX(), MyFrame. this.getY() ); MyFrame.this.setVisible( false ); MyFrame.this.dispose(); } // end windowClosing };// end anonymous class this.addWindowListener ( windowListener); } // end hookWindowClosing } // end class MyFrame