2009-12-27 7 views
4

Je suis à la recherche en utilisant Buffer Strategy et la technique suivante décrit sur la Javadoc:Est-il possible d'effectuer un rendu actif dans Java Swing sans être sur l'EDT?

// 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()); 

}

Ce serait génial d'éviter EDT et invokeLater ou invokeAndWait lors de l'exécution d'une animation.

Mes questions:

  • Si cela est dans une application Swing ne nous devons à vous soucier de mettre l'appel à show à l'EDT?
  • Quelqu'un d'autre peut-il voir des problèmes en utilisant une application Swing?

Ceci a été inspiré par ce interesting answer à la programmation de jeux.

Répondre

2

Comme mentionné par trashdog ce n'est pas une bonne idée de le faire. Créez votre propre fil d'animation qui attirera l'image hors écran. Ensuite, poussez-le sur un support. Si paintComponent est appelé, récupère l'image courante et dessine-la sur le composant. Terminé. Regardez le modèle de rendez-vous.