January 2005
Intermediate to advanced
256 pages
6h 34m
English
The
previous tasks have used the AWT, which
seemingly nobody uses anymore. Many developers will want to create a
Swing GUI, and thus they need a movie-playing
JComponent. QuickTime for Java can provide one.
Example 2-3 presents a rewrite of the previous
BasicQTPlayer that does everything with
Swing equivalents
(JFrame instead of Frame,
JComponent instead of
Component, etc.).
Example 2-3. All-Swing simple movie player
package com.oreilly.qtjnotebook.ch02;
import quicktime.*;
import quicktime.app.view.*;
import quicktime.std.movies.*;
import quicktime.io.*;
import com.oreilly.qtjnotebook.ch01.QTSessionCheck;
import java.awt.*;
import javax.swing.*;
public class BasicSwingQTPlayer extends JFrame {
public BasicSwingQTPlayer (Movie m) throws QTException {
super ("Basic Swing QT Player");
MoviePlayer mp = new MoviePlayer (m);
QTJComponent qc = QTFactory.makeQTJComponent (mp);
JComponent jc = qc.asJComponent( );
getContentPane( ).add (jc);
pack( );
}
public static void main (String[ ] args) {
try {
QTSessionCheck.check( );
QTFile file =
QTFile.standardGetFilePreview (
QTFile.kStandardQTFileTypes);
OpenMovieFile omFile = OpenMovieFile.asRead (file);
Movie m = Movie.fromFile (omFile);
JFrame f = new BasicSwingQTPlayer (m);
f.pack( );
f.setVisible(true);
m.start( );
} catch (Exception e) {
e.printStackTrace( );
}
}
}Compile and run this example with ant run-ch02-basicswingqtplayer.
This produces a simple movie-player window—as seen in ...
Read now
Unlock full access