Swing 完成绘制时通知

发布于 2024-12-24 21:04:07 字数 310 浏览 0 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

只为一人 2024-12-31 21:04:07

通常,init() 方法会初始化小程序的组件/布局。实际的绘制是由paint()完成的。

您可以通过调用 super.paint(..) 并添加您自己的代码来重写 paint() 方法:

public void paint(Graphics g) {
   super.paint(g);
   // Add your code
}

您注意到的延迟是因为 传递给 SwingUtilities.invokeLater() 的 Runnableinit()paint() 之间的某个位置被调用

Typically, the init() method initializes the components/layout of the applet. The actual drawing is done by paint().

You can override the paint() method by calling super.paint(..) and adding your own code to it:

public void paint(Graphics g) {
   super.paint(g);
   // Add your code
}

The delay you are noticing is because the Runnable you pass to SwingUtilities.invokeLater() is invoked somewhere between init() and paint()

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文