Simple animations in Java

前端 未结 4 769
滥情空心
滥情空心 2021-01-28 15:14

I\'m attempting to code a simple animation or physics example in a Java Swing application. I have the actual windows application open and working, but I can\'t figure out how to

4条回答
  •  我在风中等你
    2021-01-28 15:48

    There are any number of ways to achieve this.

    Start by taking a look at:

    • Performing Custom Painting
    • 2D Graphics

    For details about how painting in Swing is done.

    Animation is not as simple as just pausing a small period of time and then repainting, theres acceleration and deceleration and other concepts that need to be considered.

    While you could write your own, that's not a small task, a better solution might be to use a pre-existing engine, for example...

    Then take a look at:

    • Timing Framework
    • Trident
    • java-universal-tween-engine

    Which are all examples of animation engines in Swing. While I prefer the Timing Framework as it provides me with a lower level API, this is a personal opinion. Both Trident and the JUWE seem to be geared more towards component/property based animation (which the Timing Framework can do if you want to build some of the feature sets up)

提交回复
热议问题