This question already has answers here:
I get exception when using Thread.sleep(x) or wait()
(13个回答)
6年前关闭。
我正在编写一个程序,在该程序中,在显示包含以下文本的消息框后,我关闭了系统,“您有60秒的时间,直到系统关闭”,
但是我想在此框显示运行时间后等待60秒,经过数小时的研究,我无法弄清楚该怎么做,我的AP编程老师也不能...
谁能帮我吗?
我在GUI中执行此操作,因此我认为需要一个摆动计时器,但我不确定。
这就是我所拥有的
我从我的按钮单击调用这些方法
(13个回答)
6年前关闭。
我正在编写一个程序,在该程序中,在显示包含以下文本的消息框后,我关闭了系统,“您有60秒的时间,直到系统关闭”,
但是我想在此框显示运行时间后等待60秒,经过数小时的研究,我无法弄清楚该怎么做,我的AP编程老师也不能...
谁能帮我吗?
我在GUI中执行此操作,因此我认为需要一个摆动计时器,但我不确定。
这就是我所拥有的
private void Shutdown() throws IOException {
Runtime runtime = Runtime.getRuntime();
JOptionPane.showMessageDialog(null, "You have 60 seconds until system shutdown");
timer = new Timer(60,);
Process proc = runtime.exec("shutdown -s -t 60");
}
private void Logoff() throws IOException {
Runtime runtime = Runtime.getRuntime();
JOptionPane.showMessageDialog(null, "you have 60 seconds until system logoff");
timer = new Timer(60, )
Process proc = runtime.exec("shutdown -l -t 60");
我从我的按钮单击调用这些方法
最佳答案
使用Thread.sleep(milliseconds)