home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 39 / IOPROG_39.ISO / SOFT / sdkjava40.exe / data1.cab / fg_Samples / Samples / afc11 / AFCDetect / src / AFCDetect.java next >
Encoding:
Java Source  |  2000-05-04  |  2.4 KB  |  110 lines

  1. //
  2. // (C) Copyright 1995 - 1999 Microsoft Corporation.  All rights reserved.
  3. //
  4.  
  5. import java.applet.*;
  6. import java.awt.*;
  7.  
  8. /**
  9.  *    Small Java applet which detects whether AFC is installed on the machine or
  10.  *    not. The function doesSupportAFC() returns 1 if AFC is installed and 0
  11.  *    if not. Call this function from a piece of JavaScript and do the right
  12.  *    thing in that piece of code.
  13.  *
  14.  *    @version    1.0, 8/1/97
  15.  */
  16.  
  17. public class AFCDetect extends Applet
  18. {
  19.     public AFCDetect()
  20.     {        
  21.     }
  22.  
  23.     /**
  24.      *    Applet info.
  25.      *    @returns    String with information about the applet
  26.      */
  27.     public String getAppletInfo()
  28.     {
  29.         return "Name: AFCDetect\r\n" +
  30.                "Microsoft Corp.\r\n";
  31.     }
  32.  
  33.  
  34.     /**
  35.      *    The init() method is called by AWT when an applet is first loaded or
  36.      *    reloaded. Resizes the applet to 0 by 0 pixels since we want this
  37.      *    applet to run very subtly.
  38.      */
  39.     // 
  40.     public void init()
  41.     {
  42.         // we don't want this applet taking up any space on the screen
  43.          resize(0, 0);
  44.     }
  45.         
  46.     /**
  47.      *    Main function in the applet. Called by a piece of JavaScript and
  48.      *    returns whether AFC is supported on this machine or not. 
  49.      *    
  50.      *    @returns Return 0 if AFC is not installed, and 1 if it is
  51.      */
  52.     public int doesSupportAFC()
  53.     {
  54.         // Does this by trying to load an AFC UIComponent dynamically. If this succeeds,
  55.         // we have AFC. If not, we're out of luck.
  56.     
  57.         try
  58.             {
  59.                 ClassLoader c = getClass().getClassLoader();
  60.  
  61.                 if (c == null)
  62.                     {
  63.                         return 0;
  64.                     }
  65.  
  66.                 // try to load a UIComponent. This must always exist for AFC to work.
  67.                 Object obj = c.loadClass("com.ms.ui.UIComponent");                
  68.             }
  69.         catch (ClassNotFoundException e)
  70.             {
  71.                 // afc NOT installed
  72.                 return 0;
  73.             }    
  74.     
  75.         // AFC installed
  76.         return 1;    
  77.     }
  78.     
  79.     /**
  80.      *    Obtain the full dot-separated version of AFC we're using in a string.
  81.      *    
  82.      *    @returns    Version of AFC; four fields, dot separated.
  83.      */
  84.     public String getAFCVersionString()
  85.         {
  86.             return AFCVersionManager.getPackageVersionFull("com.ms.ui");
  87.         }
  88.  
  89.     /**
  90.      *    Obtains the major version number of AFC.    
  91.      *    
  92.      *    @returns    AFC major version number
  93.      */
  94.     public int getAFCMajorVersion()
  95.         {
  96.             return AFCVersionManager.getPackageVersionMajor("com.ms.ui");
  97.         }    
  98.  
  99.     /**
  100.      *    Obtains the minor version number of AFC.    
  101.      *    
  102.      *    @returns    AFC minor version number
  103.      */
  104.     public int getAFCMinorVersion()
  105.         {
  106.             return AFCVersionManager.getPackageVersionMinor("com.ms.ui");
  107.         }    
  108.     
  109. }
  110.