FileDocCategorySizeDatePackage
ConvertToJavaImageBad.javaAPI DocExample4563Wed Nov 10 12:56:24 GMT 2004com.oreilly.qtjnotebook.ch05

ConvertToJavaImageBad

public class ConvertToJavaImageBad extends Frame implements ActionListener

Fields Summary
Movie
movie
MoviePlayer
player
MovieController
controller
QTComponent
qtc
static int
nextFrameX
static int
nextFrameY
QTImageProducer
ip
Constructors Summary
public ConvertToJavaImageBad()

        super ("QuickTime Movie");
        try {
            // get movie
            QTSessionCheck.check();
            QTFile file =
                QTFile.standardGetFilePreview (QTFile.kStandardQTFileTypes);
            OpenMovieFile omFile = OpenMovieFile.asRead(file);
            movie = Movie.fromFile(omFile);
            player = new MoviePlayer (movie);
            controller = new MovieController (movie);
            // build gui
            qtc = QTFactory.makeQTComponent (controller);
            Component c = qtc.asComponent();
            setLayout (new BorderLayout());
            add (c, BorderLayout.CENTER);
            Button imageButton = new Button ("Make Java Image");
            add (imageButton, BorderLayout.SOUTH);
            imageButton.addActionListener (this);
            movie.start();
            // set up close-to-quit
            addWindowListener (new WindowAdapter() {
                    public void windowClosing (WindowEvent we) {
                        System.exit(0);
                    }
                });
        } catch (QTException qte) {
            qte.printStackTrace();
        }
    
Methods Summary
public voidactionPerformed(java.awt.event.ActionEvent e)

        grabMovieImage();
    
public voidgrabMovieImage()

        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();
        }
    
public static voidmain(java.lang.String[] arrImAPirate)

        ConvertToJavaImageBad ctji = new ConvertToJavaImageBad();
        ctji.pack();
        ctji.setVisible(true);
        Rectangle ctjiBounds = ctji.getBounds();
        nextFrameX = ctjiBounds.x + ctjiBounds.width;
        nextFrameY = ctjiBounds.y + ctjiBounds.height;