动画 Swingworker 线程和计时器
我必须为两个图表制作动画。两张图都是相关的。
一张图显示颜色制图,另一张图显示曲线。 我从文件中获取了图表的值。
因此,我必须做三件事才能对图形进行动画处理:
- 读取文件中的值 构建一些对象数组来保存这些值
- 从读取的值逐步绘制一条曲线 从
- 读取的值在其他图形中绘制一条线
这些任务中的每一个都必须每 x 秒重复一次。 目前我正在使用 Swing 计时器和扩展 SwingWorker 的类来完成此操作。在 doInBackground 方法中,我读取文件,循环遍历值来构建我的对象并填充一个数组。
在 process 方法中,我使用一些数组来构建曲线,在 did 方法中,我绘制线条。但结果并不是我想要的。 曲线拉得太快了。例如,如果我每 2 秒执行一次计时器,那么曲线必须花费 2 秒从图表的一端到达另一端。然后我必须在另一张图中画一条线。目前,曲线每两秒绘制一次。
如果可能的话,我怎样才能在不同的线程中组织它?
I must animate two graphs. Both graphs are related.
One graph display cartography of colour, and the other is diplaying a curve.
I got values for the graph from a file.
So i must do 3 things in order to animate the graphs:
- read values in the file build some array of object to hold the values
- draw a curve progressively from the read values
- draw one line in other graph from the read values
Each of these task must be repeated every x seconds.
At the moment I'm doing it using a swing timer and a class extending SwingWorker. In the doInBackground method i read the file, loop through the values to build my object and fill an array.
In the process method I use some the array to build the curve, and in the done method I draw the line. But the result is not what I intend to do.
The curve is drawing to fast. For exemple if I execute the timer every 2 seconds then the curve must take 2 seconds from one end of the graph to reach the other end. Then I must draw one line in the other graph. At the moment the curve is drawn at once every two seconds.
How can I organize this in different thread if possible ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我建议看一下 Trident 动画库 。它将为您简化很多事情。
I'd suggest to take a look at Trident animation library. It will simplify a lot of this for you.
然后在第一个计时器触发时启动第二个计时器。
Then start a second Timer within the first timer when it fires.