FileDocCategorySizeDatePackage
BasicQTTimeDisplay.javaAPI DocExample3197Wed Nov 10 12:37:30 GMT 2004com.oreilly.qtjnotebook.ch02

BasicQTTimeDisplay

public class BasicQTTimeDisplay extends Frame implements ActionListener

Fields Summary
Movie
theMovie
Label
timeLabel
Constructors Summary
public BasicQTTimeDisplay(Movie m)

        super ("Basic QT Controller");
        theMovie = m;
        MovieController mc = new MovieController(m);
        QTComponent qc = QTFactory.makeQTComponent (mc);
        Component c = qc.asComponent();
        setLayout (new BorderLayout());
        add (c, BorderLayout.CENTER);
        timeLabel = new Label ("-:--", Label.CENTER);
        add (timeLabel, BorderLayout.SOUTH);
        javax.swing.Timer timer =
            new javax.swing.Timer (250, this);
        timer.start();
        pack();
    
Methods Summary
public voidactionPerformed(java.awt.event.ActionEvent e)

        if (theMovie == null)
                    return;
        try {
            int totalSeconds = theMovie.getTime() /
                               theMovie.getTimeScale();
            int seconds = totalSeconds % 60;
            int minutes = totalSeconds / 60;
            String secString = (seconds > 9) ?
                Integer.toString (seconds) :
                ("0" + Integer.toString (seconds));
            String minString = Integer.toString (minutes);
            timeLabel.setText (minString + ":" + secString);
        } catch (QTException qte) {
            qte.printStackTrace();
        }
    
public static voidmain(java.lang.String[] args)

        try {
            QTSessionCheck.check();
            QTFile file =
                QTFile.standardGetFilePreview (QTFile.kStandardQTFileTypes);
            OpenMovieFile omFile = OpenMovieFile.asRead (file);
            Movie m = Movie.fromFile (omFile);
            Frame f = new BasicQTTimeDisplay (m);
            f.pack();
            f.setVisible(true);
            m.start();
        } catch (Exception e) {
            e.printStackTrace();
        }