如何在2分钟不使用时自动关闭系统?

how to automatically shutdown a system when it is not used for 2 minutes?

如何在不使用时关闭系统。 如果系统有 2 分钟未使用,例如甚至未使用键盘或鼠标或系统中的任何其他应用程序。该系统应该关闭。 如何使这成为可能。

Process class 允许您从下面的 java 运行 windows/any OS 命令是片段

Process proc = runtime.exec("shutdown -s");
System.exit(0);

将上面的代码放在您的逻辑中,您希望如何调用取决于您的逻辑。

Note : Here I am guessing by system you mean your OS. if you mean just application then just System.exit(0); would suffice.

编辑:

As asked by OP to check the idle time, I think you need to implement event listeners mostly mouse and keyboard. Below are some helpful links to which will help you implement it in your program:

Java mouse motion anywhere on screen

How can I listen for key presses (within Java Swing) across all components?

上述方法是在您通过键盘或鼠标记录事件时设置一个计时器,重置计时器,否则关闭。