写个main方法,然后运行,出现一个黑色屏幕,,
在别人关闭这个黑色屏幕的时候,怎样捕捉到这个关闭的事件,然后记录下来啊

解决方案 »

  1.   

    自己写一个关闭线程,然后用Runtime.getRuntime().addShutdownHook(your_thread)for example
    Runtime.getRuntime().addShutdownHook(
        new Thread() {
            public void run() {
                PrintWriter pw = new PrintWriter(new FileOutputStream("your_file", true) 
    );
                try {
                    pw.printf("%t:%s", Calendar.getInstance().getDate(), "exit by user.");
                    pw.flush();
                    pw.close();
                } catch (Throwable e) {
                    e.printStackTrace();
                } 
            }
        };
    );