Animation Thread and EDT

后端 未结 1 1557
后悔当初
后悔当初 2021-01-27 09:09

As I discussed with Inerdia on the earlier post,
something is still strange When I\'m in some JPanel (EDT for sure-I checked with the method check) and then I call some ani

1条回答
  •  有刺的猬
    2021-01-27 10:01

    Inside of SuspendedAnimation.run() you're not on the EDT. That's where you need to use invokeLater(), not when calling Animate():

    @Override
    public void run()
    {
        // We're outside the EDT in most of run()
        m_IsAnimationNeeded = true;
        for (JPanelRailoadSquare currRailoadSquare: m_PlayerRailoadPanelsTrack)
        {
            SwingUtilities.invokeAndWait(new Runnable() {
                // The code that "talks" to Swing components has to be put on
                // the EDT
                currRailoadSquare.SetGoingTrain();
                repaint();
            });
    
            // We want to keep sleeping outside the EDT.
            try
            {
                Thread.sleep(150);
            }
            catch (InterruptedException e){}
    
            SwingUtilities.invokeAndWait(new Runnable() {
                currRailoadSquare.UnSetGoingTrain();
                repaint();                       
            }
        }
    }
    

    0 讨论(0)
提交回复
热议问题