home *** CD-ROM | disk | FTP | other *** search
/ The Best of Windows 95.com 1997 April / Win95_04974.iso / docs / 00016 / 01649.exe / data.2 / program / Java / IEExtend.java < prev    next >
Encoding:
Java Source  |  1996-10-04  |  1.4 KB  |  73 lines

  1. import java.awt.*;
  2.  
  3.  
  4. public class IEExtend
  5. {
  6.     // The IE Extend class faciliates importing variables
  7.     // in different formats
  8.  
  9.     // Modified for consistency by JAR 
  10.  
  11.    public final static int strInt(String c, int def)
  12.    {
  13.       if(c!=null && c.length() > 0)
  14.       {
  15.          try
  16.          {
  17.             return Integer.parseInt(c);
  18.          }
  19.          catch(NumberFormatException e)
  20.          {
  21.             return def;
  22.          }
  23.       }
  24.       return def;
  25.    }
  26.  
  27.    public final static double strDouble(String c, double def)
  28.    {
  29.       if(c!=null && c.length() > 0)
  30.       {
  31.          try
  32.          {
  33.             return Double.valueOf(c).doubleValue();
  34.          }
  35.          catch(NumberFormatException e)
  36.          {
  37.             return def;
  38.          }
  39.       }
  40.       return def;
  41.    }
  42.  
  43.    public final static Color strColor(String c, Color def)
  44.    {
  45.       if(c == null)
  46.          return def;
  47.       return colorFromStr(c,def);
  48.    }
  49.  
  50.    public final static Color colorFromStr(String c, Color def)
  51.    {
  52.       if(c.length() < 6)
  53.          return def;
  54.       String t;
  55.       t = new String();
  56.       t += c.charAt(0);
  57.       t += c.charAt(1);
  58.       int r = Integer.parseInt(t,16);
  59.       t = new String();
  60.       t += c.charAt(2);
  61.       t += c.charAt(3);
  62.       int g = Integer.parseInt(t,16);
  63.       t = new String();
  64.       t += c.charAt(4);
  65.       t += c.charAt(5);
  66.       int b = Integer.parseInt(t,16);
  67.  
  68.       return new Color(r,g,b);
  69.    }
  70. }
  71.  
  72.  
  73.