home *** CD-ROM | disk | FTP | other *** search
/ Oracle Video Server 3.0.3.1 / OracleVideoClient3.0.3.iso / webplugin / samples / liveconnect / java / simple / sample1 / simplejava.java < prev   
Encoding:
Java Source  |  1998-01-30  |  4.6 KB  |  166 lines

  1. //******************************************************************************
  2. // simpleJava.java:    Applet
  3. //
  4. //******************************************************************************
  5. import java.applet.*;
  6. import java.awt.*;
  7. import netscape.javascript.JSObject;    //provides access to objects
  8. import netscape.javascript.JSException; //provides access to objects
  9.  
  10. import OviObserver;                        //plug-in listener (not implemented)
  11. import OviPlayer;                        //OviPlayer interface
  12.  
  13. //==============================================================================
  14. // Main Class for applet simpleJava
  15. //
  16. //==============================================================================
  17. public class simpleJava extends Applet
  18. {
  19.     // Members for applet parameters
  20.     // <type>       <MemberVar>    = <Default Value>
  21.     //--------------------------------------------------------------------------
  22.     private String m_plgname     = "";
  23.  
  24.     //GUI Objects
  25.     //--------------------------------------------------------------------------
  26.  
  27.     Button btnPlay        = null;
  28.     Button btnPause        = null;
  29.     Button btnClose        = null;
  30.     
  31.  
  32.     JSObject document, window;
  33.     OviPlayer ovi = null;
  34.  
  35.     // The init() method is called by the AWT when an applet is first loaded or
  36.     // reloaded.  Override this method to perform whatever initialization your
  37.     // applet needs, such as initializing data structures, loading images or
  38.     // fonts, creating frame windows, setting the layout manager, or adding UI
  39.     // components.
  40.     //--------------------------------------------------------------------------
  41.     public void init()
  42.     {
  43.         // PARAMETER SUPPORT
  44.         //        The following code retrieves the value of the applet parameter
  45.         //----------------------------------------------------------------------
  46.         String param;
  47.  
  48.         // param: Parameter description
  49.         //----------------------------------------------------------------------
  50.         param = getParameter("pluginName");
  51.         if (param != null)
  52.             m_plgname = param;
  53.  
  54.         resize(320, 30);
  55.         setBackground(Color.white);
  56.  
  57.         // TODO: Place additional initialization code here
  58.         btnPlay        = new Button ("Play");
  59.         btnPause    = new Button ("Pause");
  60.         btnClose    = new Button ("Close");
  61.  
  62.         add (btnPlay);
  63.         add (btnPause);
  64.         add (btnClose);
  65.         // GET JAVASCRIPT OBJECT (document)    
  66.         // Retrieve the the document object from the Browser environment
  67.         //-------------------------------------------------------------------
  68.     }
  69.  
  70.     public void start()
  71.     {
  72.  
  73.     }
  74.  
  75.     public void stop()
  76.     {
  77.  
  78.     }
  79.  
  80.     public void destroy()
  81.     {                            /* Clean Up Pointers */
  82.         ovi            = null;
  83.         document    = null;
  84.         window        = null;
  85.         System.gc();
  86.     }
  87.     // MOUSE SUPPORT:
  88.     //        The mouseUp() method is called if the mouse button is released
  89.     // while the mouse cursor is over the applet's portion of the screen.
  90.     //--------------------------------------------------------------------------
  91.     public boolean mouseUp(Event evt, int x, int y) {
  92.  
  93.         // GRAB PLUG-IN OBJECT 
  94.         // Retrieve the plug-in object handle from the browser context
  95.         //-------------------------------------------------------------------------
  96.         ovi = getPlugin();
  97.  
  98.         boolean cond = false;
  99.         if(evt.target == btnPlay) {
  100.  
  101.             if (ovi.getState() == ovi.ST_REALIZED)
  102.                 ovi.play();
  103.             else
  104.                 ovi.resume();
  105.             cond = true;
  106.         }
  107.         if (evt.target == btnPause) {
  108.  
  109.             ovi.pause();
  110.             cond = true;
  111.         }
  112.         if (evt.target == btnClose) {
  113.  
  114.             ovi.unload();
  115.             cond = true;
  116.         }
  117.         return cond;
  118.     }
  119.  
  120.  
  121.     // GET JS OBJECT HANDLES AND POINTER TO PLUGIN
  122.     // Retrieves JavaScript Object contexts from Browswer.
  123.     // This function depends upon the Netscape supplied Java package,
  124.     // netscape.javascript. This function will NOT work under Internet
  125.     // Explorer.
  126.     //-------------------------------------------------------------------
  127.     public OviPlayer getPlugin() {
  128.  
  129.         OviPlayer    plugin    = null;
  130.         ovi                    = null;
  131.         document            = null;
  132.         window                = null;
  133.         System.gc ();        
  134.  
  135.         try {
  136.             window = JSObject.getWindow(this); //grab window obj
  137.         }        
  138.         catch(NullPointerException e) {
  139.             System.out.println("getWindow() failed in getPlugin()...");
  140.         }
  141.     
  142.         if (window != null)
  143.             try {
  144.                 document = (JSObject) window.getMember("document"); //grab document obj
  145.             }        
  146.             catch(NullPointerException e) {
  147.                 System.out.println("getMember() failed in getPlugin()...");
  148.             }
  149.         if (document != null) {
  150.             try {
  151.                 plugin = (OviPlayer) document.getMember(m_plgname);
  152.             } 
  153.             catch(NullPointerException e) {
  154.                   System.out.println("unable to grab plugin");
  155.             }
  156.         }
  157.         else {
  158.             System.out.println("Document null in getPlugin()...\n");
  159.         }
  160.  
  161.         return plugin;
  162.  
  163.     } //end getPlugin
  164.  
  165. }
  166.