KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > javalogging > shutdown > TestShutdownHook


1 package net.sourceforge.javalogging.shutdown;
2
3 import javax.swing.*;
4 import java.awt.event.*;
5 import java.util.logging.*;
6
7 public class TestShutdownHook {
8
9     public static void main( String JavaDoc[] args ) {
10         Runtime.getRuntime().addShutdownHook( new Thread JavaDoc() {
11             public void run() {
12                 System.err.println( "Shutting down..." );
13                 System.err.flush();
14             }
15         });
16
17         LogManager manager = LogManager.getLogManager();
18         final Logger l = Logger.getLogger( TestShutdownHook.class.getName() );
19         l.setLevel( Level.FINEST );
20         l.fine( "Here we go..." );
21
22         JFrame frame = new JFrame( "Sample..." );
23         frame.addWindowListener( new WindowAdapter() {
24             public void windowClosing( WindowEvent evt ) {
25                 l.fine( "Closing the window and exiting..." );
26                 System.exit( 0 );
27             }
28         });
29         frame.setSize( 200, 200 );
30         frame.setVisible( true );
31     }
32 }
Popular Tags