是否有可能不被在美国东部时间执行的Java Swing活跃的渲染? [英] Is it possible to perform active rendering in Java Swing without being on the EDT?

查看:133
本文介绍了是否有可能不被在美国东部时间执行的Java Swing活跃的渲染?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我期待到使用缓冲策略< /对的Javadoc描述的>及以下技术:

I am looking into using Buffer Strategy and the following technique described on the Javadoc:

// Main loop
while (!done) {
 // Prepare for rendering the next frame
 // ...

 // Render single frame
 do {
     // The following loop ensures that the contents of the drawing buffer
     // are consistent in case the underlying surface was recreated
     do {
         // Get a new graphics context every time through the loop
         // to make sure the strategy is validated
         Graphics graphics = strategy.getDrawGraphics();

         // Render to graphics
         // ...

         // Dispose the graphics
         graphics.dispose();

         // Repeat the rendering if the drawing buffer contents 
         // were restored
     } while (strategy.contentsRestored());

     // Display the buffer
     strategy.show();

     // Repeat the rendering if the drawing buffer was lost
 } while (strategy.contentsLost());

}

这将是巨大的,以避免 EDT 的invokeLater invokeAndWait 执行动画时。

It would be great to avoid EDT and invokeLater or invokeAndWait when performing an animation.

我的问题:


  • 如果这是在Swing应用程序并不需要我们担心这会让调用显示在美国东部时间?

  • 任何人都可以看到其他人在Swing应用程序使用此什么问题?

  • If this is in a Swing application don't we need to worry about putting the call to show on the EDT?
  • Can anyone else see any problems using this in a Swing app?

这是由该有趣的答案启发游戏编程。

This was inspired by this interesting answer to game programming.

推荐答案

在一般情况下,没有。画上比事件调度线程(EDT)导致不希望的伪像,虽然结果是可以接受的。这例如演示一些权衡。我preFER安排吸取EDT使用的javax .swing.Timer ,但 是可能的其他方法。另外,您所选择的顶级集装箱可能已经实施缓冲策略

In general, no. Painting on a thread other than the event dispatch thread (EDT) results in undesirable artifacts, although the results may be acceptable. This example demonstrates some of the trade-offs. I prefer arranging to draw on the EDT using javax.swing.Timer, but other approaches are possible. Also, your chosen top-level Container may already implement a Buffer Strategy.

这篇关于是否有可能不被在美国东部时间执行的Java Swing活跃的渲染?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆