home *** CD-ROM | disk | FTP | other *** search
/ Chip Special: HTML & Java / Chip-Special_1997-01_HTML-a-Java.bin / javasdk / sdk-java.exe / SDKJava.cab / Samples / AWT / menux / menux.java < prev    next >
Encoding:
Java Source  |  1996-10-15  |  8.3 KB  |  240 lines

  1. //******************************************************************************
  2. // menux.java:    Applet
  3. //
  4. //******************************************************************************
  5. import java.applet.*;
  6. import java.awt.*;
  7. import menuxFrame;
  8. import ViewFrame;
  9.  
  10.  
  11. //==============================================================================
  12. // Main Class for applet menux
  13. //
  14. //==============================================================================
  15. public class menux extends Applet
  16. {
  17.     private Button   doIt;
  18.  
  19.     // STANDALONE APPLICATION SUPPORT:
  20.     //        m_fStandAlone will be set to true if applet is run standalone
  21.     //--------------------------------------------------------------------------
  22.     boolean m_fStandAlone = false;
  23.     public String frameMenu[] = null;
  24.  
  25.     // STANDALONE APPLICATION SUPPORT
  26.     //     The GetParameter() method is a replacement for the getParameter() method
  27.     // defined by Applet. This method returns the value of the specified parameter;
  28.     // unlike the original getParameter() method, this method works when the applet
  29.     // is run as a standalone application, as well as when run within an HTML page.
  30.     // This method is called by GetParameters().
  31.     //---------------------------------------------------------------------------
  32.     String GetParameter(String strName, String args[])
  33.     {
  34.         if (args == null)
  35.         {
  36.             // Running within an HTML page, so call original getParameter().
  37.             //-------------------------------------------------------------------
  38.             return getParameter(strName);
  39.         }
  40.  
  41.         // Running as standalone application, so parameter values are obtained from
  42.         // the command line. The user specifies them as follows:
  43.         //
  44.         //    JView menux param1=<val> param2=<"val with spaces"> ...
  45.         //-----------------------------------------------------------------------
  46.         int    i;
  47.         String strArg    = strName + "=";
  48.         String strValue = null;
  49.  
  50.         for (i = 0; i < args.length; i++)
  51.         {
  52.             if (strArg.equalsIgnoreCase(args[i].substring(0, strArg.length())))
  53.             {
  54.                 // Found matching parameter on command line, so extract its value.
  55.                 // If in double quotes, remove the quotes.
  56.                 //---------------------------------------------------------------
  57.                 strValue= args[i].substring(strArg.length());
  58.                 if (strValue.startsWith("\""))
  59.                 {
  60.                     strValue = strValue.substring(1);
  61.                     if (strValue.endsWith("\""))
  62.                         strValue = strValue.substring(0, strValue.length() - 1);
  63.                 }
  64.             }
  65.         }
  66.  
  67.         return strValue;
  68.     }
  69.  
  70.     // STANDALONE APPLICATION SUPPORT
  71.     //     The GetParameters() method retrieves the values of each of the applet's
  72.     // parameters and stores them in variables. This method works both when the
  73.     // applet is run as a standalone application and when it's run within an HTML
  74.     // page.  When the applet is run as a standalone application, this method is
  75.     // called by the main() method, which passes it the command-line arguments.
  76.     // When the applet is run within an HTML page, this method is called by the
  77.     // init() method with args == null.
  78.     //---------------------------------------------------------------------------
  79.     void GetParameters(String args[])
  80.     {
  81.     }
  82.  
  83.     // STANDALONE APPLICATION SUPPORT
  84.     //     The main() method acts as the applet's entry point when it is run
  85.     // as a standalone application. It is ignored if the applet is run from
  86.     // within an HTML page.
  87.     //--------------------------------------------------------------------------
  88.     public static void main(String args[])
  89.     {
  90.         // Create Toplevel Window to contain applet menux
  91.         //----------------------------------------------------------------------
  92.         menuxFrame frame = new menuxFrame("menux");
  93.  
  94.         // Must show Frame before we size it so insets() will return valid values
  95.         //----------------------------------------------------------------------
  96.         frame.show();
  97.         frame.hide();
  98.         frame.resize(frame.insets().left + frame.insets().right  + 320,
  99.                      frame.insets().top  + frame.insets().bottom + 240);
  100.  
  101.         // The following code starts the applet running within the frame window.
  102.         // It also calls GetParameters() to retrieve parameter values from the
  103.         // command line, and sets m_fStandAlone to true to prevent init() from
  104.         // trying to get them from the HTML page.
  105.         //----------------------------------------------------------------------
  106.         menux applet_menux = new menux();
  107.  
  108.         frame.add("Center", applet_menux);
  109.         applet_menux.m_fStandAlone = true;
  110.         applet_menux.GetParameters(args);
  111.         applet_menux.init();
  112.         applet_menux.start();
  113.         applet_menux.frameMenu = frame.frameMenu;
  114.         frame.show();
  115.     }
  116.  
  117.     // menux Class Constructor
  118.     //--------------------------------------------------------------------------
  119.     public menux()
  120.     {
  121.         // TODO: Add constructor code here
  122.     }
  123.  
  124.     // APPLET INFO SUPPORT:
  125.     //        The getAppletInfo() method returns a string describing the applet's
  126.     // author, copyright date, or miscellaneous information.
  127.     //--------------------------------------------------------------------------
  128.     public String getAppletInfo()
  129.     {
  130.         return "Name: menux\r\n" +
  131.                "Author: Ramesh G\r\n" +
  132.                "Created with Microsoft Visual J++ Version 1.0";
  133.     }
  134.  
  135.     // PARAMETER SUPPORT
  136.     //        The getParameterInfo() method returns an array of strings describing
  137.     // the parameters understood by this applet.
  138.     //
  139.     // menux Parameter Information:
  140.     //  { "Name", "Type", "Description" },
  141.     //--------------------------------------------------------------------------
  142.     public String[][] getParameterInfo()
  143.     {
  144.         String[][] info =
  145.         {
  146.             { "", "", "" }
  147.         };
  148.         return info;        
  149.     }
  150.  
  151.     // The init() method is called by the AWT when an applet is first loaded or
  152.     // reloaded.  Override this method to perform whatever initialization your
  153.     // applet needs, such as initializing data structures, loading images or
  154.     // fonts, creating frame windows, setting the layout manager, or adding UI
  155.     // components.
  156.     //--------------------------------------------------------------------------
  157.     public void init()
  158.     {
  159.         if (!m_fStandAlone)
  160.             GetParameters(null);
  161.         // If you use a ResourceWizard-generated "control creator" class to
  162.         // arrange controls in your applet, you may want to call its
  163.         // CreateControls() method from within this method. Remove the following
  164.         // call to resize() before adding the call to CreateControls();
  165.         // CreateControls() does its own resizing.
  166.         //----------------------------------------------------------------------
  167.         resize(100, 50);
  168.         doIt = new Button("Start MenuX Frame");
  169.         
  170.         setLayout(new GridLayout(1, 1, 0, 0));
  171.         add(doIt);
  172.         show();
  173.     }
  174.  
  175.     // Place additional applet clean up code here.  destroy() is called when
  176.     // when you applet is terminating and being unloaded.
  177.     //-------------------------------------------------------------------------
  178.     public void destroy()
  179.     {
  180.         // TODO: Place applet cleanup code here
  181.     }
  182.  
  183.     // menux Paint Handler
  184.     //--------------------------------------------------------------------------
  185.     public void paint(Graphics g)
  186.     {
  187.         // ANIMATION SUPPORT:
  188.         //        The following code displays a status message until all the
  189.         // images are loaded. Then it calls displayImage to display the current
  190.         // image.
  191.         //----------------------------------------------------------------------
  192.             g.drawString("MenuX...", 10, 20);
  193.  
  194.         // TODO: Place additional applet Paint code here
  195.     }
  196.  
  197.     //        The start() method is called when the page containing the applet
  198.     // first appears on the screen. The AppletWizard's initial implementation
  199.     // of this method starts execution of the applet's thread.
  200.     //--------------------------------------------------------------------------
  201.     public void start()
  202.     {
  203.  
  204.     }
  205.     
  206.     //        The stop() method is called when the page containing the applet is
  207.     // no longer on the screen. The AppletWizard's initial implementation of
  208.     // this method stops execution of the applet's thread.
  209.     //--------------------------------------------------------------------------
  210.     public void stop()
  211.     {
  212.  
  213.     }
  214.  
  215.  
  216.  
  217.     public boolean action(Event e, Object arg)
  218.     {
  219.         Object target = e.target;
  220.  
  221.  
  222.  
  223.         if( target == doIt )
  224.         {            
  225.             ViewFrame vFrame;
  226. //
  227. // Start the frame with menubarx
  228. //
  229.             vFrame = new ViewFrame("MenuX in Java!");
  230.             vFrame.resize(640, 480);
  231.             vFrame.show();
  232.             vFrame.startWindow(this, frameMenu);
  233.             return true;
  234.         }
  235.         
  236.         return false;
  237.     }
  238.  
  239. }
  240.