在 java repaint() 中调用 2 个函数,然后调用 func1(),但首先调用 func1(),然后调用 repaint()。为什么?
我在java中使用2个类class1
和class2
,它们都位于不同的包中。 class2
中定义了一个 paintComponent()
和一个 test()
。我按以下顺序从 class1 调用这些方法..
objclass2.repaint()
objclass2.test()
objclass2.repaint()
但我不知道为什么首先执行 test()
。接下来执行 repaint()
..加上第二个 repaint()
没有全部执行..为什么会这样?
编辑
for(int i=0;i<170;i++)
{
az.animate(i);
try {
Thread.sleep(160);
} catch (InterruptedException ee) {
ee.printStackTrace();
}
}
animate method():-
pd.setCurrentAltitudeScaleValue(val);
azl.update();
azl.repaint();
在 azl.paintComponent()
中,我正在绘制一些东西。每次 for 时都会调用 animate 方法
循环执行,但它不会再次调用 repaint()
。意味着 repaint
方法仅被调用一次,尽管 animate()
被一次又一次的召唤..
I am using 2 classes class1
and class2
, in java, both being in different packages. class2
has a paintComponent()
and a test()
defined in it. I am calling these methods from class1 in the following sequence..
objclass2.repaint()
objclass2.test()
objclass2.repaint()
but I dont know why test()
is executed first. repaint()
is executed next.. plus the second repaint()
is not executed as all.. Why is it so??
EDIT
for(int i=0;i<170;i++)
{
az.animate(i);
try {
Thread.sleep(160);
} catch (InterruptedException ee) {
ee.printStackTrace();
}
}
animate method():-
pd.setCurrentAltitudeScaleValue(val);
azl.update();
azl.repaint();
and in the azl.paintComponent()
I am drawing a few things.. The animate method is being called every time the for
loop executes but it doesnot call the repaint()
again.. means repaint
method is called only once though the animate()
is called again and again..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我假设您的意思是 PaintComponent() 正在表现出您提到的行为。请记住:
如果你的程序的设计确实依赖于调用paintCompoent()的顺序,那么我建议你选择不同的设计。
I assume you mean that paintComponent() is exhibiting the behaviour you mention. Bear in mind that:
If the design of your program really relies on the order in which paintCompoent() is called, then I would suggest you choose a different design.