Zoo2.java
import java.awt.*;
import java.awt.event.*;
import quicktime.QTSession;
import quicktime.QTException;
import quicktime.app.display.QTCanvas;
/**
* QTZoo Module 2 - Playing a movie
* This application requires QuickTime for Java
*
* @author Michael Hopkins
* @author Levi Brown
* @author Apple Computer, Inc.
* @version 2.0 11/15/1999
*
* Revision History
* ---------------------------------------------------------------------------
* 12/2/99 MSH added slightly better error handling, reformatting and comments
* 12/02/99 MSH removed superfluous imports, improved formatting and added comments
*
*/
public class Zoo2 extends Frame
{
static public int WIDTH = 640;
static public int HEIGHT = 480;
/**
* Zoo constructor
* @param string title of window
*/
public Zoo2( String s )
{
super(s);
setResizable( false ); // we don't want the window to resize
setBounds( 0, 0, WIDTH, HEIGHT ); // make window 640x480
QTCanvas myQTCanvas = new QTCanvas( QTCanvas.kInitialSize, 0.5F, 0.5F );
add( myQTCanvas );
AnimalPane zebraPane = new AnimalPane();// load media
try
{
myQTCanvas.setClient( zebraPane.getCompositor(), true );
}
catch ( QTException e )
{
e.printStackTrace();
}
addWindowListener( new WindowAdapter() // anonymous inner class for handling window events
{
public void windowClosing( WindowEvent we )
{
QTSession.close(); // shut down QT and clean up
dispose(); // destroy window
}
public void windowClosed( WindowEvent we )
{
System.exit( 0 ); // exit to shell
}
});
}
/**
* Main entry point for the application
*/
public static void main( String[] args )
{
try
{
QTSession.open(); // perform native QuickTime initialization
Zoo2 appWindow = new Zoo1( "QTZoo2" ); // create a new application window
appWindow.show(); // make the window visible
appWindow.toFront(); // bring it to the front
}
catch ( Exception e ) // handle any exceptions
{
QTSession.close();
e.printStackTrace();
}
}
}
AnimalPane.java
import java.io.IOException;
import java.io.FileNotFoundException;
import quicktime.app.QTFactory;
import quicktime.app.anim.Compositor;
import quicktime.app.image.GraphicsImporterDrawer;
import quicktime.app.image.ImagePresenter;
import quicktime.app.image.ImageUtil;
import quicktime.app.players.MoviePresenter;
import quicktime.io.QTFile;
import quicktime.io.OpenMovieFile;
import quicktime.qd.QDRect;
import quicktime.qd.QDGraphics;
import quicktime.qd.QDColor;
import quicktime.qd.QDConstants;
import quicktime.std.StdQTConstants;
import quicktime.std.movies.Movie;
import quicktime.QTSession;
import quicktime.QTException;
/**
* QTZoo Module 2 - Draws an image and displays a movie about zebras
*
* @author Michael Hopkins
* @author Levi Brown
* @author Apple Computer, Inc.
* @version 1.0 11/15/1999
*
* Revision History
* ---------------------------------------------------------------------------------
* 12/02/99 MSH cleaned up code, added comments
*
*/
public class AnimalPane
{
/**
* Public default constructor
* Creates the map button, and sets up the listeners
*/
public AnimalPane()
{
QDRect size = new QDRect(Zoo2.WIDTH, Zoo2.HEIGHT);
try
{
QDGraphics gw = new QDGraphics( size ); // create a new graphics object
compositor = new Compositor( gw, QDColor.white, 30, 1 );
QTFile imageFile = new QTFile(
QTFactory.findAbsolutePath( "data/zebra/ZebraBackground.jpg" ));
GraphicsImporterDrawer drawer = new GraphicsImporterDrawer( imageFile );
ImagePresenter presenter = ImagePresenter.fromGraphicsImporterDrawer( drawer );
presenter.setLocation( 110, 110 ); // set location of movie within compositor
compositor.addMember( presenter, 2 ); // add image presenter to compositor in 2nd layer
Movie m = makeMovie( new QTFile(
QTFactory.findAbsolutePath( "data/zebra/Zebra.mov" )));
md = new MoviePresenter( m ); // create presenter from movie file
compositor.addMember( md, 1 ); // add presenter to compositor
compositor.getTimer().setRate(1); // start compositor
md.setRate(1); // start movie
}
catch ( IOException e ) // catch any errors
{
e.printStackTrace();
}
catch ( QTException e )
{
e.printStackTrace();
}
}
public Compositor getCompositor( ) { return compositor; } // returns the compositor associated with the animal pane
/**
* Opens the movie file and sets it up to be played.
* @param f a QTFile representing the movie to initialize.
* @return the movie, ready to play
*/
protected Movie makeMovie( QTFile f ) throws IOException, QTException
{
OpenMovieFile movieFile = OpenMovieFile.asRead(f);
Movie m = Movie.fromFile( movieFile );
m.getTimeBase().setFlags( StdQTConstants.loopTimeBase );// we want the movie to loop
return m;
}
protected Compositor compositor;
protected MoviePresenter md;
}