Java: Handle logoff or shutdown on Windows and Linux

后端 未结 4 1998
面向向阳花
面向向阳花 2021-01-06 04:13

Is there a way for a Java GUI application to respond to system shutdown or logoff events, other than to use JNI? (On Windows, the JNI would use WM_QUERYENDSESSION, on Linux

4条回答
  •  失恋的感觉
    2021-01-06 04:51

    This doesn't answer the question, but addresses part of it.

    In a Unix GUI session, I consider the right way to handle the logoff event is to save the document to a temporary file and save the information in the session state. During the session recovery, the program can reload the temporary file and take up where it left off. No need to ask the user about saving or not.

    I just wish more software did transparent session save and recovery. Too many programs reopen with empty document windows because the GUI framework used does that much but none of the rest of the work has been done to actually handle any meaningful program state.

提交回复
热议问题