[英]delay in an java applet program without using threads
Is it possible in java to make the program to sleep or wait for a particular time peroid ? 在Java中是否可以使程序休眠或等待特定时间?
As in C++ we do delay(1000);
像在C ++中一样,我们执行
delay(1000);
. 。 I am writing a java applet which does not include threads , but I want it to delay the execution of some statements.
我正在编写一个不包含线程的java小程序,但我希望它延迟某些语句的执行。 Its a clock(Digital) applet.
它是一个时钟(数字)小程序。 so I need to make part of my applet code to delay for 1 second.
所以我需要将我的applet代码的一部分延迟1秒。
You don't want to do that. 你不想那样做。 sleeping for a second in the Event Dispatching Thread will prevent any event processing during that time.
在事件调度线程中睡眠一秒钟将阻止在此期间进行任何事件处理。 One second may not be that much, but in general this is not a good practice.
一秒钟可能不会那么多,但是通常这不是一个好习惯。
What you want to do is setup a timer with a 1s period. 您要设置的计时器时间为1秒。
Yes. 是。 It is possible.
有可能的。 Do a little research into the
Thread.sleep()
method as well as Timers as well as... 对
Thread.sleep()
方法,Timers以及...进行一些研究。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.