try {
// lazy instantiation of ImageProducer
if (ip == null) {
QDRect bounds = movie.getBounds();
Dimension dimBounds =
new Dimension (bounds.getWidth(), bounds.getHeight());
ip = new QTImageProducer (player, dimBounds);
}
// stop movie to take picture
boolean wasPlaying = false;
if (movie.getRate() > 0) {
movie.stop();
wasPlaying = true;
}
// convert from MoviePlayer to java.awt.Image
Image image = Toolkit.getDefaultToolkit().createImage (ip);
// make a swing icon out of it and show it in a frame
ImageIcon icon = new ImageIcon (image);
JLabel label = new JLabel (icon);
JFrame frame = new JFrame ("Java image");
frame.getContentPane().add(label);
frame.pack();
frame.setLocation (nextFrameX += 10,
nextFrameY += 10);
frame.setVisible(true);
// restart movie
if (wasPlaying)
movie.start();
} catch (QTException qte) {
qte.printStackTrace();
}