home *** CD-ROM | disk | FTP | other *** search
/ Netscape Plug-Ins Developer's Kit / Netscape_Plug-Ins_Developers_Kit.iso / source / Chap15 / npavi / HTML / AVITEST.JAV < prev    next >
Encoding:
Text File  |  1996-05-10  |  2.2 KB  |  105 lines

  1. /*
  2.  */
  3. import AviObserver;
  4. import AviPlayer;
  5. import java.awt.Panel;
  6. import java.awt.TextField;
  7. import java.awt.Button;
  8. import java.awt.Event;
  9. import java.awt.BorderLayout;
  10. import java.awt.Frame;
  11. import java.applet.Applet;
  12. import netscape.javascript.JSObject;
  13.  
  14. /**
  15.  * An interactive test of the Graphics.drawArc and Graphics.fillArc
  16.  * routines. Can be run either as a standalone application by
  17.  * typing "java ArcTest" or as an applet in the AppletViewer.
  18.  */
  19. public class AviTest extends Applet implements AviObserver{
  20.     MediaControl control;
  21.  
  22.     public void init() {
  23.         setLayout(new BorderLayout());
  24.         add("Center", control = new MediaControl(getDocument()));
  25.         control.enable();
  26.     }
  27.  
  28.     public static void main(String args[]) {
  29.         Frame f = new Frame("AviTest");
  30.         AviTest aviTest = new AviTest();
  31.  
  32.         aviTest.init();
  33.  
  34.         f.add("Center", aviTest);
  35.         f.resize(300, 30);
  36.         f.show();
  37.     }
  38.  
  39.     public void onStop() {
  40.         control.resetButton();
  41.     }
  42.  
  43.     public void onPositionChange(int newPosition) {
  44.         control.updateFrame(newPosition);
  45.     }
  46.  
  47.     public JSObject getDocument() {
  48.         return (JSObject)JSObject.getWindow(this).getMember("document");
  49.     }
  50.  
  51. }
  52.     
  53.  
  54. class MediaControl extends Panel {
  55.     TextField s;
  56.     Button play;
  57.     Button stop;
  58.  
  59.     JSObject document;
  60.  
  61.     public MediaControl(JSObject doc) {
  62.         document = doc;
  63.  
  64.         add(play = new Button("Play"));
  65.         add(stop = new Button("Stop"));
  66.         add(s = new TextField("0", 4));
  67.         stop.disable();
  68.     }
  69.  
  70.     public void updateFrame(int frame) {
  71.         s.setText(String.valueOf(frame));
  72.     }
  73.  
  74.     public void resetButton() {
  75.         play.enable();
  76.         stop.disable();
  77.     }
  78.  
  79.     public boolean action(Event ev, Object arg) {
  80.         if (ev.target instanceof Button) {
  81.             AviPlayer avi = (AviPlayer)document.getMember("avi");
  82.             
  83.             String label = (String)arg;
  84.             if (label == "Play") {
  85.                 // look AviPlayer.java for exaplanation
  86.                 avi.play(true);
  87.                 play.disable();
  88.                 stop.enable();
  89.                 return true;
  90.             }
  91.             else {
  92.                 // look AviPlayer.java for exaplanation
  93.                 avi.stop(true);
  94.                 stop.disable();
  95.                 play.enable();
  96.                 return true;
  97.             }
  98.         }
  99.  
  100.         return false;
  101.     }
  102.  
  103. }
  104.         
  105.