暂停油漆 [英] Pause on paint

查看:81
本文介绍了暂停油漆的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,所以我自己做了大量的搜索和测试,所以我觉得是时候问专家了。


我是目前正在构建一个Java applet。它的目的是找到一个哈密尔顿循环...那部分我工作得很好......但我的问题是这个,我希望我的图形从一点到另一点改变从黑到红的颜色。我可以让他们改变颜色,但我似乎无法让它一直更新。我在调用repaint()之后调用repaint()之前尝试添加暂停,甚至在重绘函数中也是如此。但是我得到了相同的结果。


我最接近的是放一个在applet上绘制每一行后暂停,但这只能让我得到最终的结果。


这里'进行了更改并调用了repaint()...

Okay, so I''ve done a fair amount of searching and testing on my own so I figure it''s time to ask the experts.

I''m currently building a Java applet. It''s purpose is to find a hamiltonian cycle... that part I got working fine... but my problem is this, I want my graph to change colors from black to red as it goes from point to point. I can get them to change colors but i can''t seem to get it to update consistently. I''ve tried adding pauses before calling repaint() after calling repaint() and even in the repaint function but I get relatively the same result.

The closest I got was putting a pause after each line is drawn on the applet, but this only managed to get me the final result painted slowly.

here''s where changes are made and repaint() is called...

展开 | 选择 | Wrap | 行号

推荐答案

您需要阅读有关使用SwingTimer进行动画的内容。谷歌那些东西,你应该得到一些有用的信息。
You need to read about doing animation using the SwingTimer. Google those things and you should get some useful information.


SwingTimers帮助我弄清楚如何更及时地调用重绘。但是,它仍会打印出图表的最终结果,而不是打印定期更新。我认为这是因为每隔X毫秒调用重绘一次,其余的代码都会继续执行,因此在X秒内已经计算出整个路径。我需要的是在绘制函数试图赶上时暂停其余执行的方法...

感谢btw的建议,摆动定时器会派上用场未来所以我很高兴我了解了它们:)
SwingTimers helped me figure out how to call repaint in a more timely manner. However it would still print out the final result of the graph instead of printing periodic updates. I think this is because while repaint is being called every X milliseconds the rest of the code keeps executing, so in that X seconds the entire path is already calculated. What I would need is a way to pause the rest of the execution while the paint function tries to catch up...

Thanks for the suggestion btw, swing timers will come in handy in the future so I''m glad I learned about them :)


为什么不发布你现在拥有的东西?
Why don''t you post what you have now?


这篇关于暂停油漆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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