2009-12-27 2 views
4

나는 Buffer Strategy을 사용하여에보고하고 다음과 같은 기술은 자바 독에 설명 : 애니메이션을 수행 할 때EDT없이 Java Swing에서 활성 렌더링을 수행 할 수 있습니까?

// Main loop 
while (!done) { 
// Prepare for rendering the next frame 
// ... 

// Render single frame 
do { 
    // The following loop ensures that the contents of the drawing buffer 
    // are consistent in case the underlying surface was recreated 
    do { 
     // Get a new graphics context every time through the loop 
     // to make sure the strategy is validated 
     Graphics graphics = strategy.getDrawGraphics(); 

     // Render to graphics 
     // ... 

     // Dispose the graphics 
     graphics.dispose(); 

     // Repeat the rendering if the drawing buffer contents 
     // were restored 
    } while (strategy.contentsRestored()); 

    // Display the buffer 
    strategy.show(); 

    // Repeat the rendering if the drawing buffer was lost 
} while (strategy.contentsLost()); 

}

EDTinvokeLater 또는 invokeAndWait을 피하기 위해 좋은 것입니다.

내 질문 : 이것은 우리가 동부 서머 타임에 show에 전화를 넣어 대해 걱정할 필요가 없습니다 스윙 응용 프로그램에있는 경우

  • ?
  • 누구든지 Swing 앱에서이 문제를 사용하여 문제를 볼 수 있습니까?

이것은 게임 프로그래밍에 대해 interesting answer에서 영감을 얻었습니다.

답변

2

trashdog에서 언급했듯이 그렇게하는 것은 좋지 않습니다. 스크린 이미지를 그릴 자체 애니메이션 스레드를 만듭니다. 그런 다음 일부 홀더로 밀어 넣으십시오. paintComponent가 호출되면 현재 이미지를 가져 와서 구성 요소에 그립니다. 끝난. 랑데뷰 패턴을보십시오.

관련 문제