简体   繁体   中英

Calling 2 functions in java repaint() and then func1() but func1() is being called first and then repaint(). why?

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..

I assume you mean that paintComponent() is exhibiting the behaviour you mention. Bear in mind that:

  • when you call repaint(), that basically flags the component to say "this component needs re-painting at the next convenient moment from the event thread"
  • calls to paintComponent() can be coalesced.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM