home *** CD-ROM | disk | FTP | other *** search
/ AOL File Library: 12,000 to 12,999 / 12000.zip / AOLDLs / Online-Tools / Java-Applets / JAVAAPPS.lzh / JAVAAPPS / GLOWBUTT / GLOWBUTT.EXE / glowbutton.java < prev   
Encoding:
Java Source  |  1996-03-11  |  3.0 KB  |  133 lines

  1. // Glow buttons - the name says it all
  2.  
  3.  
  4. // Amit C. (ConnectSoft Ruksun, Pune, India) amit@maverick.corus.co.in
  5.  
  6.  
  7.  
  8.  
  9.  
  10. import java.awt.Color ;
  11.  
  12.  
  13. import java.awt.Graphics;
  14.  
  15.  
  16. import java.util.Date;
  17.  
  18.  
  19. import java.lang.String ;
  20.  
  21.  
  22. import java.util.StringTokenizer;
  23.  
  24.  
  25.  
  26.  
  27.  
  28. public class glowbutton extends java.applet.Applet implements Runnable 
  29.  
  30.  
  31. {
  32.  
  33.  
  34.     Thread    GlowThread ;
  35.  
  36.  
  37.     int        i = 0 ;
  38.  
  39.  
  40.     Color    GlowColor1 = new Color(0,0,0);
  41.  
  42.  
  43.     Color    GlowColor2= new Color(0,0,0);
  44.  
  45.  
  46.     Color    GlowColor3 = new Color(0,0,0);
  47.  
  48.  
  49.  
  50.  
  51.  
  52.     public void init() 
  53.  
  54.  
  55.     {
  56.  
  57.  
  58.                                     // The glowing colors
  59.  
  60.  
  61.         GlowColor1 = StringToColor (
  62.  
  63.  
  64.                                MygetStringParam("glowcolor1", "0,0,0"), 
  65.  
  66.  
  67.                             Color.cyan ) ;
  68.  
  69.  
  70.  
  71.  
  72.  
  73.         GlowColor2 = StringToColor (
  74.  
  75.  
  76.                                MygetStringParam("glowcolor2", "0,0,0"), 
  77.  
  78.  
  79.                             Color.darkGray ) ;
  80.  
  81.  
  82.  
  83.  
  84.  
  85.         GlowColor3 = StringToColor (
  86.  
  87.  
  88.                                MygetStringParam("glowcolor3", "0,0,0"), 
  89.  
  90.  
  91.                             Color.magenta ) ;
  92.  
  93.  
  94.     }
  95.  
  96.  
  97.     public void start() 
  98.  
  99.  
  100.     {
  101.  
  102.  
  103.         if (GlowThread == null) 
  104.  
  105.  
  106.         {
  107.  
  108.  
  109.             GlowThread = new Thread(this, "Glow");
  110.  
  111.  
  112.             GlowThread.start();
  113.  
  114.  
  115.         }
  116.  
  117.  
  118.     }
  119.  
  120.  
  121.  
  122.  
  123.  
  124.     public void run() 
  125.  
  126.  
  127.     {
  128.  
  129.  
  130.         while (GlowThread != null) 
  131.  
  132.  
  133.         {
  134.  
  135.  
  136.             repaint();
  137.  
  138.  
  139.             try 
  140.  
  141.  
  142.             {
  143.  
  144.  
  145.                 GlowThread.sleep(200);            // Sleep for 800 millisec
  146.  
  147.  
  148.             } 
  149.  
  150.  
  151.             catch (InterruptedException e)
  152.  
  153.  
  154.             {
  155.  
  156.  
  157.             }
  158.  
  159.  
  160.         }
  161.  
  162.  
  163.     }
  164.  
  165.  
  166.  
  167.  
  168.  
  169.     public void paint(Graphics g) 
  170.  
  171.  
  172.     {
  173.  
  174.  
  175.         g.setColor (Color.black ) ;    
  176.  
  177.  
  178.         g.drawRect (0, 0, size().width - 1, size().height - 1 ) ;
  179.  
  180.  
  181.  
  182.  
  183.  
  184.         g.setColor (Color.gray ) ;    
  185.  
  186.  
  187.         g.drawRect (1, 1, size().width - 2, size().height - 2 ) ;
  188.  
  189.  
  190.         g.drawRect (2, 2, size().width - 3, size().height - 3 ) ;
  191.  
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.         if ( i == 0 )                // What color to fill in with!
  200.  
  201.  
  202.             g.setColor (GlowColor1 ) ;    
  203.  
  204.  
  205.         else
  206.  
  207.  
  208.             if (i == 1 )
  209.  
  210.  
  211.                 g.setColor (GlowColor2 ) ;    
  212.  
  213.  
  214.             else
  215.  
  216.  
  217.                 g.setColor (GlowColor3 ) ;    
  218.  
  219.  
  220.  
  221.  
  222.  
  223.         g.fillRect (3, 3, size().width - 4, size().height - 4 ) ;
  224.  
  225.  
  226.         i = i+ 1 ;
  227.  
  228.  
  229.         i = i % 3 ;
  230.  
  231.  
  232.     }
  233.  
  234.  
  235.  
  236.  
  237.  
  238.     public void stop() 
  239.  
  240.  
  241.     {
  242.  
  243.  
  244.         GlowThread.stop();
  245.  
  246.  
  247.         GlowThread = null;
  248.  
  249.  
  250.     }
  251.  
  252.  
  253.  
  254.  
  255.  
  256.     // A changed version of getparam
  257.  
  258.  
  259.     public    String    MygetStringParam (String att, String def) 
  260.  
  261.  
  262.     {
  263.  
  264.  
  265.         String ret;
  266.  
  267.  
  268.  
  269.  
  270.  
  271.         try 
  272.  
  273.  
  274.         {
  275.  
  276.  
  277.             ret = getParameter(att);
  278.  
  279.  
  280.             if (ret.length() < 1)
  281.  
  282.  
  283.                 return def;
  284.  
  285.  
  286.             else
  287.  
  288.  
  289.                 return ret;
  290.  
  291.  
  292.         } 
  293.  
  294.  
  295.         catch(Exception e) 
  296.  
  297.  
  298.         {
  299.  
  300.  
  301.             return def;
  302.  
  303.  
  304.         }
  305.  
  306.  
  307.     }   
  308.  
  309.  
  310.  
  311.  
  312.  
  313.     // Given a string parses it to get the colors  
  314.  
  315.  
  316.     public Color StringToColor (String strColor_p, Color clrDefault_p ) 
  317.  
  318.  
  319.     {
  320.  
  321.  
  322.         if (strColor_p.length ( ) == 0) 
  323.  
  324.  
  325.         { 
  326.  
  327.  
  328.             return clrDefault_p ;
  329.  
  330.  
  331.         }
  332.  
  333.  
  334.  
  335.  
  336.  
  337.         int r;
  338.  
  339.  
  340.         int g;
  341.  
  342.  
  343.         int b;
  344.  
  345.  
  346.                                         // Delimiter is ','
  347.  
  348.  
  349.         StringTokenizer st = new StringTokenizer (strColor_p, ",") ;
  350.  
  351.  
  352.  
  353.  
  354.  
  355.         try 
  356.  
  357.  
  358.         {
  359.  
  360.  
  361.             r = Integer.valueOf(st.nextToken()).intValue();
  362.  
  363.  
  364.             g = Integer.valueOf(st.nextToken()).intValue();
  365.  
  366.  
  367.             b = Integer.valueOf(st.nextToken()).intValue();
  368.  
  369.  
  370.             return new Color(r,g,b);
  371.  
  372.  
  373.         }
  374.  
  375.  
  376.         catch (Exception e) 
  377.  
  378.  
  379.         {
  380.  
  381.  
  382.             return clrDefault_p;
  383.  
  384.  
  385.         }
  386.  
  387.  
  388.     }
  389.  
  390.  
  391.  
  392.  
  393.  
  394. }
  395.  
  396.  
  397.