home *** CD-ROM | disk | FTP | other *** search
Java Source | 1998-01-30 | 4.6 KB | 166 lines |
- //******************************************************************************
- // simpleJava.java: Applet
- //
- //******************************************************************************
- import java.applet.*;
- import java.awt.*;
- import netscape.javascript.JSObject; //provides access to objects
- import netscape.javascript.JSException; //provides access to objects
-
- import OviObserver; //plug-in listener (not implemented)
- import OviPlayer; //OviPlayer interface
-
- //==============================================================================
- // Main Class for applet simpleJava
- //
- //==============================================================================
- public class simpleJava extends Applet
- {
- // Members for applet parameters
- // <type> <MemberVar> = <Default Value>
- //--------------------------------------------------------------------------
- private String m_plgname = "";
-
- //GUI Objects
- //--------------------------------------------------------------------------
-
- Button btnPlay = null;
- Button btnPause = null;
- Button btnClose = null;
-
-
- JSObject document, window;
- OviPlayer ovi = null;
-
- // The init() method is called by the AWT when an applet is first loaded or
- // reloaded. Override this method to perform whatever initialization your
- // applet needs, such as initializing data structures, loading images or
- // fonts, creating frame windows, setting the layout manager, or adding UI
- // components.
- //--------------------------------------------------------------------------
- public void init()
- {
- // PARAMETER SUPPORT
- // The following code retrieves the value of the applet parameter
- //----------------------------------------------------------------------
- String param;
-
- // param: Parameter description
- //----------------------------------------------------------------------
- param = getParameter("pluginName");
- if (param != null)
- m_plgname = param;
-
- resize(320, 30);
- setBackground(Color.white);
-
- // TODO: Place additional initialization code here
- btnPlay = new Button ("Play");
- btnPause = new Button ("Pause");
- btnClose = new Button ("Close");
-
- add (btnPlay);
- add (btnPause);
- add (btnClose);
- // GET JAVASCRIPT OBJECT (document)
- // Retrieve the the document object from the Browser environment
- //-------------------------------------------------------------------
- }
-
- public void start()
- {
-
- }
-
- public void stop()
- {
-
- }
-
- public void destroy()
- { /* Clean Up Pointers */
- ovi = null;
- document = null;
- window = null;
- System.gc();
- }
- // MOUSE SUPPORT:
- // The mouseUp() method is called if the mouse button is released
- // while the mouse cursor is over the applet's portion of the screen.
- //--------------------------------------------------------------------------
- public boolean mouseUp(Event evt, int x, int y) {
-
- // GRAB PLUG-IN OBJECT
- // Retrieve the plug-in object handle from the browser context
- //-------------------------------------------------------------------------
- ovi = getPlugin();
-
- boolean cond = false;
- if(evt.target == btnPlay) {
-
- if (ovi.getState() == ovi.ST_REALIZED)
- ovi.play();
- else
- ovi.resume();
- cond = true;
- }
- if (evt.target == btnPause) {
-
- ovi.pause();
- cond = true;
- }
- if (evt.target == btnClose) {
-
- ovi.unload();
- cond = true;
- }
- return cond;
- }
-
-
- // GET JS OBJECT HANDLES AND POINTER TO PLUGIN
- // Retrieves JavaScript Object contexts from Browswer.
- // This function depends upon the Netscape supplied Java package,
- // netscape.javascript. This function will NOT work under Internet
- // Explorer.
- //-------------------------------------------------------------------
- public OviPlayer getPlugin() {
-
- OviPlayer plugin = null;
- ovi = null;
- document = null;
- window = null;
- System.gc ();
-
- try {
- window = JSObject.getWindow(this); //grab window obj
- }
- catch(NullPointerException e) {
- System.out.println("getWindow() failed in getPlugin()...");
- }
-
- if (window != null)
- try {
- document = (JSObject) window.getMember("document"); //grab document obj
- }
- catch(NullPointerException e) {
- System.out.println("getMember() failed in getPlugin()...");
- }
- if (document != null) {
- try {
- plugin = (OviPlayer) document.getMember(m_plgname);
- }
- catch(NullPointerException e) {
- System.out.println("unable to grab plugin");
- }
- }
- else {
- System.out.println("Document null in getPlugin()...\n");
- }
-
- return plugin;
-
- } //end getPlugin
-
- }
-