next up previous
Next: The QuickTime for Java Up: The Quicktime API: A Previous: The Quicktime API: A

The QTSimpleApplet Example

A good starting point for understanding QuickTime for Java is the QTSimpleApplet program from the QuickTime for Java SDK. The code listing for is given below:

 * QuickTime for Java SDK Sample Code

   Usage subject to restrictions in SDK License Agreement
 * Copyright:  1996-1999 Apple Computer, Inc.

import java.applet.Applet;
import java.awt.*;

import quicktime.*;

import;	// for exceptions

public class QTSimpleApplet extends Applet {
	private Drawable myQTContent;
	private QTCanvas myQTCanvas;
	public void init () {
		try {
			// this is a workaround required by a bug in the loading
			// mechanism of applets using the JavaPlugin on Netscape on Win
			if (QTSession.isInitialized() == false);

				// set up a QTCanvas which will disply its content 
				// at its original size of smaller and centered in the space given
				// to the QTCanvas when the applet is layed out
			setLayout (new BorderLayout());
			myQTCanvas = new QTCanvas (QTCanvas.kInitialSize, 0.5F, 0.5F);
			add (myQTCanvas, "Center");		
			QTFile file = new QTFile (getCodeBase().getFile() + getParameter("file"));
			myQTContent = QTFactory.makeDrawable (file);
		} catch (QTException qtE) {
				// something wrong with the content but QT itself is OK
			if (QTSession.isInitialized())
				myQTContent = ImageDrawer.getQTLogo();
				throw new RuntimeException (qtE.getMessage());		
		} catch (FileNotFoundException fnfE) {
			myQTContent = ImageDrawer.getQTLogo();
		} catch (IOException ioE) {
				// the IOException would occur as a violation of
				// java security settings on the user machine - throw it again
			throw new SecurityException (ioE.getMessage());

	public void start () { 
		try { // if QT was not successfully initialized the QTCanvas will be null
			if (myQTCanvas != null)
				myQTCanvas.setClient (myQTContent, true);			
		} catch (QTException e) {
	public void stop () { 
		if (myQTCanvas != null)
	public void destroy () {

The out of QTSimpleApplet running in an applet viewer is shown in Fig. 9.1.

{\tt QTSimpleApplet} Output

The things to note about this program are:

The basic operation of the code is as follows:

next up previous
Next: The QuickTime for Java Up: The Quicktime API: A Previous: The Quicktime API: A
Dave Marshall