Swing 完成绘制时通知
Swing 小程序完成绘制后收到通知的正确方法是什么?我正在编写一些计时代码来测量小程序需要多长时间,并希望包括显示任何图形的时间。
在执行所有绘图的 init() 方法结束时,我将一个 Runnable 传递给 SwingUtilities.invokeLater,它休眠了 10 秒。我看到图形显示之前有延迟。我本以为延迟会在图形之后发生,因为我知道它会在绘图调用之后排队。我尝试将此睡眠测试代码移至 start() 并得到相同的结果。
根据我对 javascript 警报消息的测试,似乎在绘制图形之前也会触发放置在 HTML body 标记上的 onload 事件。
What is the correct way to be notified once a Swing applet has finished its drawing? I'm writing some timing code to measure how long the applet takes and want to include the time to display any graphics.
At the end of my init() method which performs all the drawing, I passed in a Runnable to SwingUtilities.invokeLater that slept for 10 seconds. I saw the delay prior to the graphics being displayed. I would have thought that the delay would occur after the graphics since I had understood it would be queued up after the drawing calls. I tried moving this sleep test code to start() and got the same results.
Based on my testing with a javascript alert message, it appears that an onload event placed on a HTML body tag is also triggered prior to the graphics being drawn.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通常,
init()
方法会初始化小程序的组件/布局。实际的绘制是由paint()
完成的。您可以通过调用
super.paint(..)
并添加您自己的代码来重写paint()
方法:您注意到的延迟是因为
传递给
在SwingUtilities.invokeLater()
的 Runnableinit()
和paint()
之间的某个位置被调用Typically, the
init()
method initializes the components/layout of the applet. The actual drawing is done bypaint()
.You can override the
paint()
method by callingsuper.paint(..)
and adding your own code to it:The delay you are noticing is because the
Runnable
you pass toSwingUtilities.invokeLater()
is invoked somewhere betweeninit()
andpaint()