home *** CD-ROM | disk | FTP | other *** search
Java Source | 1996-10-15 | 8.3 KB | 240 lines |
- //******************************************************************************
- // menux.java: Applet
- //
- //******************************************************************************
- import java.applet.*;
- import java.awt.*;
- import menuxFrame;
- import ViewFrame;
-
-
- //==============================================================================
- // Main Class for applet menux
- //
- //==============================================================================
- public class menux extends Applet
- {
- private Button doIt;
-
- // STANDALONE APPLICATION SUPPORT:
- // m_fStandAlone will be set to true if applet is run standalone
- //--------------------------------------------------------------------------
- boolean m_fStandAlone = false;
- public String frameMenu[] = null;
-
- // STANDALONE APPLICATION SUPPORT
- // The GetParameter() method is a replacement for the getParameter() method
- // defined by Applet. This method returns the value of the specified parameter;
- // unlike the original getParameter() method, this method works when the applet
- // is run as a standalone application, as well as when run within an HTML page.
- // This method is called by GetParameters().
- //---------------------------------------------------------------------------
- String GetParameter(String strName, String args[])
- {
- if (args == null)
- {
- // Running within an HTML page, so call original getParameter().
- //-------------------------------------------------------------------
- return getParameter(strName);
- }
-
- // Running as standalone application, so parameter values are obtained from
- // the command line. The user specifies them as follows:
- //
- // JView menux param1=<val> param2=<"val with spaces"> ...
- //-----------------------------------------------------------------------
- int i;
- String strArg = strName + "=";
- String strValue = null;
-
- for (i = 0; i < args.length; i++)
- {
- if (strArg.equalsIgnoreCase(args[i].substring(0, strArg.length())))
- {
- // Found matching parameter on command line, so extract its value.
- // If in double quotes, remove the quotes.
- //---------------------------------------------------------------
- strValue= args[i].substring(strArg.length());
- if (strValue.startsWith("\""))
- {
- strValue = strValue.substring(1);
- if (strValue.endsWith("\""))
- strValue = strValue.substring(0, strValue.length() - 1);
- }
- }
- }
-
- return strValue;
- }
-
- // STANDALONE APPLICATION SUPPORT
- // The GetParameters() method retrieves the values of each of the applet's
- // parameters and stores them in variables. This method works both when the
- // applet is run as a standalone application and when it's run within an HTML
- // page. When the applet is run as a standalone application, this method is
- // called by the main() method, which passes it the command-line arguments.
- // When the applet is run within an HTML page, this method is called by the
- // init() method with args == null.
- //---------------------------------------------------------------------------
- void GetParameters(String args[])
- {
- }
-
- // STANDALONE APPLICATION SUPPORT
- // The main() method acts as the applet's entry point when it is run
- // as a standalone application. It is ignored if the applet is run from
- // within an HTML page.
- //--------------------------------------------------------------------------
- public static void main(String args[])
- {
- // Create Toplevel Window to contain applet menux
- //----------------------------------------------------------------------
- menuxFrame frame = new menuxFrame("menux");
-
- // Must show Frame before we size it so insets() will return valid values
- //----------------------------------------------------------------------
- frame.show();
- frame.hide();
- frame.resize(frame.insets().left + frame.insets().right + 320,
- frame.insets().top + frame.insets().bottom + 240);
-
- // The following code starts the applet running within the frame window.
- // It also calls GetParameters() to retrieve parameter values from the
- // command line, and sets m_fStandAlone to true to prevent init() from
- // trying to get them from the HTML page.
- //----------------------------------------------------------------------
- menux applet_menux = new menux();
-
- frame.add("Center", applet_menux);
- applet_menux.m_fStandAlone = true;
- applet_menux.GetParameters(args);
- applet_menux.init();
- applet_menux.start();
- applet_menux.frameMenu = frame.frameMenu;
- frame.show();
- }
-
- // menux Class Constructor
- //--------------------------------------------------------------------------
- public menux()
- {
- // TODO: Add constructor code here
- }
-
- // APPLET INFO SUPPORT:
- // The getAppletInfo() method returns a string describing the applet's
- // author, copyright date, or miscellaneous information.
- //--------------------------------------------------------------------------
- public String getAppletInfo()
- {
- return "Name: menux\r\n" +
- "Author: Ramesh G\r\n" +
- "Created with Microsoft Visual J++ Version 1.0";
- }
-
- // PARAMETER SUPPORT
- // The getParameterInfo() method returns an array of strings describing
- // the parameters understood by this applet.
- //
- // menux Parameter Information:
- // { "Name", "Type", "Description" },
- //--------------------------------------------------------------------------
- public String[][] getParameterInfo()
- {
- String[][] info =
- {
- { "", "", "" }
- };
- return info;
- }
-
- // 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()
- {
- if (!m_fStandAlone)
- GetParameters(null);
- // If you use a ResourceWizard-generated "control creator" class to
- // arrange controls in your applet, you may want to call its
- // CreateControls() method from within this method. Remove the following
- // call to resize() before adding the call to CreateControls();
- // CreateControls() does its own resizing.
- //----------------------------------------------------------------------
- resize(100, 50);
- doIt = new Button("Start MenuX Frame");
-
- setLayout(new GridLayout(1, 1, 0, 0));
- add(doIt);
- show();
- }
-
- // Place additional applet clean up code here. destroy() is called when
- // when you applet is terminating and being unloaded.
- //-------------------------------------------------------------------------
- public void destroy()
- {
- // TODO: Place applet cleanup code here
- }
-
- // menux Paint Handler
- //--------------------------------------------------------------------------
- public void paint(Graphics g)
- {
- // ANIMATION SUPPORT:
- // The following code displays a status message until all the
- // images are loaded. Then it calls displayImage to display the current
- // image.
- //----------------------------------------------------------------------
- g.drawString("MenuX...", 10, 20);
-
- // TODO: Place additional applet Paint code here
- }
-
- // The start() method is called when the page containing the applet
- // first appears on the screen. The AppletWizard's initial implementation
- // of this method starts execution of the applet's thread.
- //--------------------------------------------------------------------------
- public void start()
- {
-
- }
-
- // The stop() method is called when the page containing the applet is
- // no longer on the screen. The AppletWizard's initial implementation of
- // this method stops execution of the applet's thread.
- //--------------------------------------------------------------------------
- public void stop()
- {
-
- }
-
-
-
- public boolean action(Event e, Object arg)
- {
- Object target = e.target;
-
-
-
- if( target == doIt )
- {
- ViewFrame vFrame;
- //
- // Start the frame with menubarx
- //
- vFrame = new ViewFrame("MenuX in Java!");
- vFrame.resize(640, 480);
- vFrame.show();
- vFrame.startWindow(this, frameMenu);
- return true;
- }
-
- return false;
- }
-
- }
-