在 JFrame 中淡入和淡出 Jpanels
我想在一个全局 JFrame 中制作一个包含多个 JPanel 的游戏。我想切换这些 JPanel,但要有漂亮的动画,例如淡入和淡出。如何淡出 JPanel、将 JPanel 切换到新 JPanel,然后淡入新 JPanel(最好没有外部库)?
多谢
I would like to make a game with multiple JPanels in a single global JFrame. I would like to switch these JPanels but with a nice animation like fade in and fade out. How would you be able to fade a JPanel out, switch the JPanel to a new one, and fade the new in (preferably without an external library)?
Thanks a lot
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
也许http://filthyrichclients.org/
有一些不错的想法和示例(在线)可以开始使用。它包含许多摆动动画细节。
Maybe http://filthyrichclients.org/
has some nice ideas and examples(online) to get started. It contains many swing animation details.
可以在面板和组件上执行类似的操作以使它们淡出:
您可能需要在其中抛出 Thread.sleep() 。
另请参阅:
但请注意,这会影响整个应用程序
Could possibly do something like this on the panel and components to make them fade out:
You will probably need to throw a Thread.sleep() in there.
Also have a look at:
But note that this does the entire application
作为参考,
FlashTest< /code>
展示了如何通过更改颜色的饱和度来淡入淡出,而
AlphaTest
展示了如何通过更改颜色的 Alpha 来淡入淡出。For reference,
FlashTest
shows how to fade by changing a color's saturation, whileAlphaTest
shows how to fade by changing a color's alpha.我建议创建一个虚拟 javafx 节点,为其设置动画,并将虚拟节点的不透明度属性与您的 swing 项目绑定。
会是这样的
I suggest creating a dummy javafx node, setting an animation for it, and binding the opacity property of the dummy node with your swing item.
it would be something like this