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 / JAVEX / JAVEX.EXE / javex.java < prev    next >
Encoding:
Java Source  |  1996-03-09  |  19.9 KB  |  550 lines

  1. /*
  2.  
  3.  
  4.  * javex.java - 19 Jan 1996 - Version 1.00
  5.  
  6.  
  7.  *
  8.  
  9.  
  10.  * Note: This source code is subject to perpetual refinement!
  11.  
  12.  
  13.  *
  14.  
  15.  
  16.  * Copyright 1996 by Bill Giel
  17.  
  18.  
  19.  *
  20.  
  21.  
  22.  * E-mail: rvdi@usa.nai.net
  23.  
  24.  
  25.  * WWW: http://www.nai.net/~rvdi/home.htm
  26.  
  27.  
  28.  *
  29.  
  30.  
  31.  *
  32.  
  33.  
  34.  * Permission to use, copy, modify, and distribute this software
  35.  
  36.  
  37.  * and its documentation for NON-COMMERCIAL or COMMERCIAL purposes and
  38.  
  39.  
  40.  * without fee is hereby granted, provided that any use properly credits
  41.  
  42.  
  43.  * the author, i.e. "Javex Clock courtesy of <A HREF="mailto:rvdi@usa.nai.net">
  44.  
  45.  
  46.  * Bill Giel</A>.
  47.  
  48.  
  49.  * 
  50.  
  51.  
  52.  * 
  53.  
  54.  
  55.  * THE AUTHOR MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY
  56.  
  57.  
  58.  * OF THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
  59.  
  60.  
  61.  * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  62.  
  63.  
  64.  * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. THE AUTHOR SHALL NOT BE LIABLE
  65.  
  66.  
  67.  * FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
  68.  
  69.  
  70.  * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
  71.  
  72.  
  73.  * 
  74.  
  75.  
  76.  * THIS SOFTWARE IS NOT DESIGNED OR INTENDED FOR USE OR RESALE AS ON-LINE
  77.  
  78.  
  79.  * CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING FAIL-SAFE
  80.  
  81.  
  82.  * PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, AIRCRAFT
  83.  
  84.  
  85.  * NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT LIFE
  86.  
  87.  
  88.  * SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
  89.  
  90.  
  91.  * SOFTWARE COULD LEAD DIRECTLY TO DEATH, PERSONAL INJURY, OR SEVERE
  92.  
  93.  
  94.  * PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH RISK ACTIVITIES"). YOU WOULD
  95.  
  96.  
  97.  * HAVE TO BE OUT OF YOUR MIND TO USE THIS SOFTWARE IN A HIGH-RISK ENVIRONMENT
  98.  
  99.  
  100.  * AND, AS SUCH MAY BE THE CASE,  THE AUTHOR SPECIFICALLY DISCLAIMS ANY EXPRESS
  101.  
  102.  
  103.  * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES, INCLUDING BUT NOT
  104.  
  105.  
  106.  * LIMITED TO USE OR MISUSE OF THIS SOFTWARE RESULTING IN NUCLEAR EXPLOSIONS,
  107.  
  108.  
  109.  * GLOBAL WARMING OR OZONE-LAYER DEPLETION.
  110.  
  111.  
  112.  */
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124. import java.awt.*;
  125.  
  126.  
  127. import java.applet.*;
  128.  
  129.  
  130. import java.lang.*;
  131.  
  132.  
  133. import java.util.*;
  134.  
  135.  
  136. import java.net.*;
  137.  
  138.  
  139.  
  140.  
  141.  
  142. class hms extends Date
  143.  
  144.  
  145. {
  146.  
  147.  
  148.     public hms(){super();}
  149.  
  150.  
  151.  
  152.  
  153.  
  154.     public double get_hours()
  155.  
  156.  
  157.     {
  158.  
  159.  
  160.         return (double)super.getHours()+(double)getMinutes()/60.0;
  161.  
  162.  
  163.     }
  164.  
  165.  
  166. }
  167.  
  168.  
  169.  
  170.  
  171.  
  172. abstract class clockHand
  173.  
  174.  
  175. {
  176.  
  177.  
  178.     protected int baseX[], baseY[];
  179.  
  180.  
  181.     protected int transX[],transY[];
  182.  
  183.  
  184.     protected int numberOfPoints;
  185.  
  186.  
  187.  
  188.  
  189.  
  190.     public clockHand(int originX, int originY, int length,int thickness,int points){
  191.  
  192.  
  193.         baseX= new int[points]; baseY=new int[points];
  194.  
  195.  
  196.         transX= new int[points]; transY=new int[points];
  197.  
  198.  
  199.         initiallizePoints(originX,originY,length,thickness);
  200.  
  201.  
  202.         numberOfPoints=points;
  203.  
  204.  
  205.     }
  206.  
  207.  
  208.  
  209.  
  210.  
  211.     abstract protected void initiallizePoints(  int originX,
  212.  
  213.  
  214.                                                 int originY,
  215.  
  216.  
  217.                                                 int length,
  218.  
  219.  
  220.                                                 int thickness);
  221.  
  222.  
  223.                                                 
  224.  
  225.  
  226.     abstract public void draw(Color color, double angle, Graphics g);
  227.  
  228.  
  229.  
  230.  
  231.  
  232.     protected void transform(double angle)
  233.  
  234.  
  235.     {
  236.  
  237.  
  238.         for(int i=0;i<numberOfPoints;i++){
  239.  
  240.  
  241.             transX[i]=(int)(    (baseX[0]-baseX[i]) * Math.cos(angle) -
  242.  
  243.  
  244.                                 (baseY[0]-baseY[i]) * Math.sin(angle) +
  245.  
  246.  
  247.                                  baseX[0]);
  248.  
  249.  
  250.                                  
  251.  
  252.  
  253.             transY[i]=(int)(    (baseX[0]-baseX[i]) * Math.sin(angle) +
  254.  
  255.  
  256.                                 (baseY[0]-baseY[i]) * Math.cos(angle) +
  257.  
  258.  
  259.                                  baseY[0]);
  260.  
  261.  
  262.         }
  263.  
  264.  
  265.     }
  266.  
  267.  
  268. }
  269.  
  270.  
  271.  
  272.  
  273.  
  274. class sweepHand extends clockHand
  275.  
  276.  
  277. {
  278.  
  279.  
  280.     public sweepHand(int originX,int originY, int length, int points)
  281.  
  282.  
  283.     {
  284.  
  285.  
  286.         super(originX,originY,length,0,points);
  287.  
  288.  
  289.     }
  290.  
  291.  
  292.  
  293.  
  294.  
  295.     protected void initiallizePoints(int originX,int originY, int length, int unused)
  296.  
  297.  
  298.     {
  299.  
  300.  
  301.         unused=unused;  //We don't use the thickness parameter in this class
  302.  
  303.  
  304.                         //This comes from habit to prevent compiler warning
  305.  
  306.  
  307.                         //concerning unused arguments.
  308.  
  309.  
  310.         
  311.  
  312.  
  313.         baseX[0]=originX; baseY[0]=originY;
  314.  
  315.  
  316.         baseX[1]=originX; baseY[1]=originY-length/5;
  317.  
  318.  
  319.         baseX[2]=originX; baseY[2]=originY+length;
  320.  
  321.  
  322.     }
  323.  
  324.  
  325.  
  326.  
  327.  
  328.     public void draw(Color color, double angle, Graphics g)
  329.  
  330.  
  331.     {
  332.  
  333.  
  334.         transform(angle);
  335.  
  336.  
  337.         g.setColor(color);
  338.  
  339.  
  340.         g.drawLine(transX[1],transY[1],transX[2],transY[2]);
  341.  
  342.  
  343.     }    
  344.  
  345.  
  346. }
  347.  
  348.  
  349.  
  350.  
  351.  
  352. class hmHand extends clockHand
  353.  
  354.  
  355. {
  356.  
  357.  
  358.     public hmHand(int originX,int originY, int length,int thickness, int points){
  359.  
  360.  
  361.         super(originX,originY,length,thickness,points);
  362.  
  363.  
  364.     }    
  365.  
  366.  
  367.  
  368.  
  369.  
  370.     protected void initiallizePoints(   int originX,
  371.  
  372.  
  373.                                         int originY,
  374.  
  375.  
  376.                                         int length,
  377.  
  378.  
  379.                                         int thickness)
  380.  
  381.  
  382.     {
  383.  
  384.  
  385.         baseX[0]=originX;
  386.  
  387.  
  388.         baseY[0]=originY;
  389.  
  390.  
  391.         
  392.  
  393.  
  394.         baseX[1]=baseX[0]-thickness/2;
  395.  
  396.  
  397.         baseY[1]=baseY[0]+thickness/2;
  398.  
  399.  
  400.         
  401.  
  402.  
  403.         baseX[2]=baseX[1];
  404.  
  405.  
  406.         baseY[2]=baseY[0]+length- thickness;
  407.  
  408.  
  409.         
  410.  
  411.  
  412.         baseX[3]=baseX[0];
  413.  
  414.  
  415.         baseY[3]=baseY[0]+length;
  416.  
  417.  
  418.         
  419.  
  420.  
  421.         baseX[4]=baseX[0]+thickness/2;
  422.  
  423.  
  424.         baseY[4]=baseY[2];
  425.  
  426.  
  427.         
  428.  
  429.  
  430.         baseX[5]=baseX[4];
  431.  
  432.  
  433.         baseY[5]=baseY[1];
  434.  
  435.  
  436.     }
  437.  
  438.  
  439.  
  440.  
  441.  
  442.     public void draw(Color color,double angle, Graphics g)
  443.  
  444.  
  445.     {
  446.  
  447.  
  448.         transform(angle);
  449.  
  450.  
  451.         g.setColor(color);
  452.  
  453.  
  454.         g.fillPolygon(transX,transY,numberOfPoints);
  455.  
  456.  
  457.     }
  458.  
  459.  
  460. }
  461.  
  462.  
  463.  
  464.  
  465.  
  466. public class javex extends Applet implements Runnable
  467.  
  468.  
  469. {
  470.  
  471.  
  472.     //some DEFINE'd constants
  473.  
  474.  
  475.     static final int BACKGROUND=0;              //Background image index
  476.  
  477.  
  478.     static final int LOGO=1;                    //Logo image index
  479.  
  480.  
  481.     static final String JAVEX="JAVEX";          //Default text on clock face
  482.  
  483.  
  484.     static final double MINSEC=0.104719755;     //Radians per minute or second
  485.  
  486.  
  487.     static final double HOUR=0.523598776;       //Radians per hour
  488.  
  489.  
  490.  
  491.  
  492.  
  493.     Thread clockThread = null;
  494.  
  495.  
  496.  
  497.  
  498.  
  499.     //User options, see getParameterInfo(), below.
  500.  
  501.  
  502.     int width = 100;
  503.  
  504.  
  505.     int height = 100;
  506.  
  507.  
  508.     Color bgColor = new Color(0,0,0);
  509.  
  510.  
  511.     Color faceColor = new Color(0,0,0);
  512.  
  513.  
  514.     Color sweepColor = new Color(255,0,0);
  515.  
  516.  
  517.     Color minuteColor = new Color (192,192,192);
  518.  
  519.  
  520.     Color hourColor = new Color (255,255,255);
  521.  
  522.  
  523.     Color textColor = new Color (255,255,255);
  524.  
  525.  
  526.     Color caseColor = new Color (0,0,0);
  527.  
  528.  
  529.     Color trimColor = new Color (192,192,192);
  530.  
  531.  
  532.     String logoString=null;
  533.  
  534.  
  535.     
  536.  
  537.  
  538.     Image images[] = new Image[2]; //Array to hold optional images
  539.  
  540.  
  541.  
  542.  
  543.  
  544.     boolean isPainted=false; //Force painting on first update, if not painted
  545.  
  546.  
  547.  
  548.  
  549.  
  550.     //Center point of clock
  551.  
  552.  
  553.     int x1,y1;
  554.  
  555.  
  556.  
  557.  
  558.  
  559.     //Array of points for triangular icon at 12:00
  560.  
  561.  
  562.     int xPoints[]=new int[3], yPoints[]=new int[3];
  563.  
  564.  
  565.  
  566.  
  567.  
  568.     //Class to hold time, with method to return (double)(hours + minutes/60)
  569.  
  570.  
  571.     hms cur_time;
  572.  
  573.  
  574.  
  575.  
  576.  
  577.     //The clock's seconds, minutes, and hours hands.
  578.  
  579.  
  580.     sweepHand sweep;
  581.  
  582.  
  583.     hmHand  minuteHand,
  584.  
  585.  
  586.             hourHand;
  587.  
  588.  
  589.  
  590.  
  591.  
  592.     //The last parameters used to draw the hands.
  593.  
  594.  
  595.     double lastHour;
  596.  
  597.  
  598.     int lastMinute,lastSecond;
  599.  
  600.  
  601.  
  602.  
  603.  
  604.     //The font used for text and date.
  605.  
  606.  
  607.     Font font;
  608.  
  609.  
  610.  
  611.  
  612.  
  613.     //Offscreen image and device context, for buffered output.
  614.  
  615.  
  616.     Image offScrImage;
  617.  
  618.  
  619.     Graphics offScrGC;
  620.  
  621.  
  622.  
  623.  
  624.  
  625.     // Use to test background image, if any.
  626.  
  627.  
  628.     MediaTracker tracker;
  629.  
  630.  
  631.  
  632.  
  633.  
  634.    
  635.  
  636.  
  637.     int minDimension;   // Ensure a round clock if applet is not square.
  638.  
  639.  
  640.     int originX;        // Upper left corner of a square enclosing the clock
  641.  
  642.  
  643.     int originY;        // with respect to applet area.
  644.  
  645.  
  646.     
  647.  
  648.  
  649.  
  650.  
  651.  
  652.     //Users' parameters - self-explanatory?
  653.  
  654.  
  655.     public String[][] getParameterInfo()
  656.  
  657.  
  658.     {
  659.  
  660.  
  661.         String[][] info = {
  662.  
  663.  
  664.             {"width",       "int",      "width of the applet, in pixels"},
  665.  
  666.  
  667.             {"height",      "int",      "height of the applet, in pixels"},
  668.  
  669.  
  670.             {"bgColor",     "string",   "hex color triplet of the background, i.e. 000000 for black <black>"},
  671.  
  672.  
  673.             {"faceColor",   "string",   "hex color triplet of clock face, i.e. 000000 for black <black>"},
  674.  
  675.  
  676.             {"sweepColor",  "string",   "hex color triplet of seconds hand, i.e. FF0000 for red <red>"},
  677.  
  678.  
  679.             {"minuteColor", "string",   "hex color triplet of minutes hand, i.e. C0C0C0 for lt.gray <lt.gray>"},
  680.  
  681.  
  682.             {"hourColor",   "string",   "hex color triplet of hours hand, i.e. FFFFFF for white <white>"},
  683.  
  684.  
  685.             {"textColor",   "string",   "hex color triplet of numbers, etc., i.e. FFFFFF for white <white>"},
  686.  
  687.  
  688.             {"caseColor",   "string",   "hex color triplet of case, i.e. 000000 for black <black>"},
  689.  
  690.  
  691.             {"trimColor",   "string",   "hex color triplet of case outliners, i.e. C0C0C0 for lt.gray <lt.gray>"}, 
  692.  
  693.  
  694.             {"bgImageURL",  "string",   "URL of background image, if any <null>"},
  695.  
  696.  
  697.             {"logoString",  "string",   "Name to display on watch face <JAVEX>"},
  698.  
  699.  
  700.             {"logoImageURL","string",   "URL of logo image to display on watch face <null>"},
  701.  
  702.  
  703.         };
  704.  
  705.  
  706.         return info;
  707.  
  708.  
  709.     }
  710.  
  711.  
  712.  
  713.  
  714.  
  715.     //Applet name, author and info lines
  716.  
  717.  
  718.     public String getAppletInfo()
  719.  
  720.  
  721.     {
  722.  
  723.  
  724.         return "JAVEX - analog clock applet by Bill Giel, 17 Jan 96\nhttp://www.nai.net/~rvdi/home.htm  or  rvdi@usa.nai.net";
  725.  
  726.  
  727.     }
  728.  
  729.  
  730.  
  731.  
  732.  
  733.     void showURLerror(Exception e)
  734.  
  735.  
  736.     {
  737.  
  738.  
  739.         String errorMsg = "JAVEX URL error: "+e;
  740.  
  741.  
  742.         showStatus(errorMsg);
  743.  
  744.  
  745.         System.err.println(errorMsg);
  746.  
  747.  
  748.     }
  749.  
  750.  
  751.  
  752.  
  753.  
  754.     // This lets us create clocks of various sizes, but with the same
  755.  
  756.  
  757.     // proportions.
  758.  
  759.  
  760.     private int size(int percent)
  761.  
  762.  
  763.     {
  764.  
  765.  
  766.         return (int)((double)percent/100.0 * (double)minDimension);
  767.  
  768.  
  769.     }
  770.  
  771.  
  772.  
  773.  
  774.  
  775.     public void init()
  776.  
  777.  
  778.     {
  779.  
  780.  
  781.         URL imagesURL[] = new URL[2];
  782.  
  783.  
  784.         String szImagesURL[] = new String[2];
  785.  
  786.  
  787.         tracker = new MediaTracker(this);
  788.  
  789.  
  790.                 
  791.  
  792.  
  793.         String paramString    = getParameter( "WIDTH"  );
  794.  
  795.  
  796.         if( paramString != null )
  797.  
  798.  
  799.             width = Integer.valueOf(paramString).intValue();
  800.  
  801.  
  802.             
  803.  
  804.  
  805.         paramString   = getParameter( "HEIGHT" );
  806.  
  807.  
  808.         if( paramString != null )
  809.  
  810.  
  811.             height = Integer.valueOf(paramString).intValue();
  812.  
  813.  
  814.             
  815.  
  816.  
  817.         paramString    = getParameter( "BGCOLOR");
  818.  
  819.  
  820.         if( paramString != null )
  821.  
  822.  
  823.             bgColor=parseColorString(paramString);
  824.  
  825.  
  826.             
  827.  
  828.  
  829.         paramString    = getParameter( "FACECOLOR");
  830.  
  831.  
  832.         if( paramString != null )
  833.  
  834.  
  835.             faceColor=parseColorString(paramString);
  836.  
  837.  
  838.             
  839.  
  840.  
  841.         paramString    = getParameter( "SWEEPCOLOR");
  842.  
  843.  
  844.         if( paramString != null )
  845.  
  846.  
  847.             sweepColor=parseColorString(paramString);
  848.  
  849.  
  850.             
  851.  
  852.  
  853.         paramString    = getParameter( "MINUTECOLOR");
  854.  
  855.  
  856.         if( paramString != null )
  857.  
  858.  
  859.             minuteColor=parseColorString(paramString);
  860.  
  861.  
  862.  
  863.  
  864.  
  865.         paramString    = getParameter( "HOURCOLOR");
  866.  
  867.  
  868.         if( paramString != null )
  869.  
  870.  
  871.             hourColor=parseColorString(paramString);                
  872.  
  873.  
  874.  
  875.  
  876.  
  877.         paramString    = getParameter( "TEXTCOLOR");
  878.  
  879.  
  880.         if( paramString != null )
  881.  
  882.  
  883.             textColor=parseColorString(paramString);
  884.  
  885.  
  886.  
  887.  
  888.  
  889.         paramString    = getParameter( "CASECOLOR");
  890.  
  891.  
  892.         if( paramString != null )
  893.  
  894.  
  895.             caseColor=parseColorString(paramString);
  896.  
  897.  
  898.  
  899.  
  900.  
  901.         paramString    = getParameter( "TRIMCOLOR");
  902.  
  903.  
  904.         if( paramString != null )
  905.  
  906.  
  907.             trimColor=parseColorString(paramString);
  908.  
  909.  
  910.  
  911.  
  912.  
  913.         logoString  = getParameter( "LOGOSTRING");
  914.  
  915.  
  916.         if( logoString == null )
  917.  
  918.  
  919.             logoString=JAVEX;
  920.  
  921.  
  922.         else if(logoString.length() > 8)
  923.  
  924.  
  925.             logoString= logoString.substring(0,8); //Max 8 characters!
  926.  
  927.  
  928.         
  929.  
  930.  
  931.         szImagesURL[BACKGROUND]  = getParameter("BGIMAGEURL");
  932.  
  933.  
  934.         szImagesURL[LOGO] = getParameter("LOGOIMAGEURL");
  935.  
  936.  
  937.  
  938.  
  939.  
  940.         for(int i=0; i<2; i++){
  941.  
  942.  
  943.             if(szImagesURL[i] != null){
  944.  
  945.  
  946.                 try{
  947.  
  948.  
  949.                     imagesURL[i]=new URL(getDocumentBase(),szImagesURL[i]);
  950.  
  951.  
  952.                 } catch (MalformedURLException e)
  953.  
  954.  
  955.                     {
  956.  
  957.  
  958.                         showURLerror(e);
  959.  
  960.  
  961.                         imagesURL[i]=null;
  962.  
  963.  
  964.                         images[i]=null;
  965.  
  966.  
  967.                     }
  968.  
  969.  
  970.                 if(imagesURL[i] != null){
  971.  
  972.  
  973.                     showStatus("Javex loading image: " + imagesURL[i].toString());
  974.  
  975.  
  976.                     images[i]=getImage(imagesURL[i]);
  977.  
  978.  
  979.                     if(images[i] != null)
  980.  
  981.  
  982.                         tracker.addImage(images[i],i);    
  983.  
  984.  
  985.                     showStatus("");                        
  986.  
  987.  
  988.                 }
  989.  
  990.  
  991.                 if(images[i] != null)
  992.  
  993.  
  994.                     try{
  995.  
  996.  
  997.                         tracker.waitForID(i);
  998.  
  999.  
  1000.                     }catch (InterruptedException e)
  1001.  
  1002.  
  1003.                         {
  1004.  
  1005.  
  1006.                             images[i]=null;
  1007.  
  1008.  
  1009.                         }
  1010.  
  1011.  
  1012.             }
  1013.  
  1014.  
  1015.             else images[i]=null;
  1016.  
  1017.  
  1018.         }
  1019.  
  1020.  
  1021.         
  1022.  
  1023.  
  1024.         cur_time=new hms();
  1025.  
  1026.  
  1027.         lastHour=-1.0;
  1028.  
  1029.  
  1030.         lastMinute=-1;
  1031.  
  1032.  
  1033.         lastSecond=-1;
  1034.  
  1035.  
  1036.  
  1037.  
  1038.  
  1039.         x1=width/2;
  1040.  
  1041.  
  1042.         y1=height/2;
  1043.  
  1044.  
  1045.  
  1046.  
  1047.  
  1048.         minDimension= Math.min(width, height);
  1049.  
  1050.  
  1051.         originX=(width-minDimension)/2;
  1052.  
  1053.  
  1054.         originY=(height-minDimension)/2;
  1055.  
  1056.  
  1057.  
  1058.  
  1059.  
  1060.         xPoints[1]=x1-size(3); xPoints[2]=x1+size(3); xPoints[0]=x1;
  1061.  
  1062.  
  1063.         yPoints[1]=y1-size(38);yPoints[2]=y1-size(38); yPoints[0]=y1-size(27);
  1064.  
  1065.  
  1066.  
  1067.  
  1068.  
  1069.         sweep=new sweepHand(x1,y1,size(40),3);
  1070.  
  1071.  
  1072.         minuteHand=new hmHand(x1,y1,size(40),size(6),6);
  1073.  
  1074.  
  1075.         hourHand=new hmHand(x1,y1,size(25),size(8),6);
  1076.  
  1077.  
  1078.  
  1079.  
  1080.  
  1081.         font=new Font("TXT",Font.BOLD,size(10));
  1082.  
  1083.  
  1084.  
  1085.  
  1086.  
  1087.         offScrImage = createImage(width,height);
  1088.  
  1089.  
  1090.         offScrGC = offScrImage.getGraphics();
  1091.  
  1092.  
  1093.     }
  1094.  
  1095.  
  1096.  
  1097.  
  1098.  
  1099.     public void start()
  1100.  
  1101.  
  1102.     {
  1103.  
  1104.  
  1105.         if(clockThread == null){
  1106.  
  1107.  
  1108.             clockThread = new Thread(this);
  1109.  
  1110.  
  1111.             clockThread.start();
  1112.  
  1113.  
  1114.         }
  1115.  
  1116.  
  1117.     }
  1118.  
  1119.  
  1120.  
  1121.  
  1122.  
  1123.     public void stop()
  1124.  
  1125.  
  1126.     {
  1127.  
  1128.  
  1129.         clockThread.stop();
  1130.  
  1131.  
  1132.         clockThread=null;
  1133.  
  1134.  
  1135.     }
  1136.  
  1137.  
  1138.     
  1139.  
  1140.  
  1141.     private void drawHands(Graphics g)
  1142.  
  1143.  
  1144.     {
  1145.  
  1146.  
  1147.     
  1148.  
  1149.  
  1150.         double angle;
  1151.  
  1152.  
  1153.         int i,j;
  1154.  
  1155.  
  1156.         int x,y;
  1157.  
  1158.  
  1159.     
  1160.  
  1161.  
  1162.         angle=MINSEC * lastSecond;
  1163.  
  1164.  
  1165.         sweep.draw(faceColor, angle, g);
  1166.  
  1167.  
  1168.  
  1169.  
  1170.  
  1171.         if(cur_time.getMinutes() != lastMinute){
  1172.  
  1173.  
  1174.             minuteHand.draw(faceColor,MINSEC*lastMinute,g);
  1175.  
  1176.  
  1177.             if(cur_time.get_hours() != lastHour)
  1178.  
  1179.  
  1180.                 hourHand.draw(faceColor,HOUR*lastHour,g);
  1181.  
  1182.  
  1183.         }
  1184.  
  1185.  
  1186.  
  1187.  
  1188.  
  1189.         g.setColor(textColor);
  1190.  
  1191.  
  1192.         g.fillRect(originX+size(12),y1-size(2),size(10),size(4));
  1193.  
  1194.  
  1195.         g.fillRect(x1-size(2),originY + minDimension-size(22),size(4),size(10));
  1196.  
  1197.  
  1198.         g.fillPolygon( xPoints, yPoints, 3);
  1199.  
  1200.  
  1201.         for(i=1;i<12;i+=3)
  1202.  
  1203.  
  1204.             for(j=i;j<i+2;j++){
  1205.  
  1206.  
  1207.                 x=(int)(x1+Math.sin(HOUR*j)*size(35));
  1208.  
  1209.  
  1210.                 y=(int)(y1-Math.cos(HOUR*j)*size(35));
  1211.  
  1212.  
  1213.                 g.fillOval(x-size(3),y-size(3),size(6),size(6));
  1214.  
  1215.  
  1216.             }
  1217.  
  1218.  
  1219.  
  1220.  
  1221.  
  1222.         //Set the font and get font info...
  1223.  
  1224.  
  1225.         g.setFont(font);
  1226.  
  1227.  
  1228.         FontMetrics fm=g.getFontMetrics();
  1229.  
  1230.  
  1231.  
  1232.  
  1233.  
  1234.         //Paint our logo...
  1235.  
  1236.  
  1237.         g.drawString(logoString,x1-fm.stringWidth(logoString)/2,y1-size(12));
  1238.  
  1239.  
  1240.  
  1241.  
  1242.  
  1243.         //Get the day of the month...
  1244.  
  1245.  
  1246.         String day=Integer.toString(cur_time.getDate(),10);
  1247.  
  1248.  
  1249.         
  1250.  
  1251.  
  1252.         //Paint it...
  1253.  
  1254.  
  1255.         g.drawString(   day,
  1256.  
  1257.  
  1258.                         originX + minDimension-size(14)-fm.stringWidth(day),
  1259.  
  1260.  
  1261.                         y1+size(5));
  1262.  
  1263.  
  1264.  
  1265.  
  1266.  
  1267.         //and put a box around it.                        
  1268.  
  1269.  
  1270.         g.drawRect( originX + minDimension-size(14)-fm.stringWidth(day)-size(2),
  1271.  
  1272.  
  1273.                     y1-size(5)-size(2),
  1274.  
  1275.  
  1276.                     fm.stringWidth(day)+size(4),
  1277.  
  1278.  
  1279.                     size(10)+size(4));
  1280.  
  1281.  
  1282.  
  1283.  
  1284.  
  1285.         if(images[LOGO] != null){
  1286.  
  1287.  
  1288.             x = originX + (minDimension-images[LOGO].getWidth(this))/2;
  1289.  
  1290.  
  1291.             y = y1 + (minDimension/2 - size(22) - images[LOGO].getHeight(this))/2;
  1292.  
  1293.  
  1294.             if(x > 0 && y > 0)
  1295.  
  1296.  
  1297.                 offScrGC.drawImage(images[LOGO], x, y, this);
  1298.  
  1299.  
  1300.         }
  1301.  
  1302.  
  1303.  
  1304.  
  1305.  
  1306.         lastHour=cur_time.get_hours();
  1307.  
  1308.  
  1309.         hourHand.draw(hourColor,HOUR*lastHour,g);
  1310.  
  1311.  
  1312.         
  1313.  
  1314.  
  1315.         lastMinute=cur_time.getMinutes();
  1316.  
  1317.  
  1318.         minuteHand.draw(minuteColor,MINSEC*lastMinute,g);        
  1319.  
  1320.  
  1321.  
  1322.  
  1323.  
  1324.         g.setColor(minuteColor);
  1325.  
  1326.  
  1327.         g.fillOval(x1-size(4),y1-size(4),size(8),size(8));
  1328.  
  1329.  
  1330.         g.setColor(sweepColor);
  1331.  
  1332.  
  1333.         g.fillOval(x1-size(3),y1-size(3),size(6),size(6));
  1334.  
  1335.  
  1336.  
  1337.  
  1338.  
  1339.         lastSecond=cur_time.getSeconds();        
  1340.  
  1341.  
  1342.         angle=MINSEC*lastSecond;
  1343.  
  1344.  
  1345.         sweep.draw(sweepColor, angle,g);
  1346.  
  1347.  
  1348.  
  1349.  
  1350.  
  1351.         g.setColor(trimColor);
  1352.  
  1353.  
  1354.         g.fillOval(x1-size(1),y1-size(1),size(2),size(2));        
  1355.  
  1356.  
  1357.     }
  1358.  
  1359.  
  1360.  
  1361.  
  1362.  
  1363.     private Color parseColorString(String colorString)
  1364.  
  1365.  
  1366.     {
  1367.  
  1368.  
  1369.         if(colorString.length()==6){
  1370.  
  1371.  
  1372.             int R = Integer.valueOf(colorString.substring(0,2),16).intValue();
  1373.  
  1374.  
  1375.             int G = Integer.valueOf(colorString.substring(2,4),16).intValue();
  1376.  
  1377.  
  1378.             int B = Integer.valueOf(colorString.substring(4,6),16).intValue();
  1379.  
  1380.  
  1381.             return new Color(R,G,B);
  1382.  
  1383.  
  1384.         }
  1385.  
  1386.  
  1387.         else return Color.lightGray;
  1388.  
  1389.  
  1390.     }
  1391.  
  1392.  
  1393.     
  1394.  
  1395.  
  1396.     public void run()
  1397.  
  1398.  
  1399.     {
  1400.  
  1401.  
  1402.         //Let's not hog the system, now...
  1403.  
  1404.  
  1405.         Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
  1406.  
  1407.  
  1408.         
  1409.  
  1410.  
  1411.         repaint();
  1412.  
  1413.  
  1414.         for(;;){
  1415.  
  1416.  
  1417.             cur_time=new hms();
  1418.  
  1419.  
  1420.             repaint();
  1421.  
  1422.  
  1423.             try{
  1424.  
  1425.  
  1426.                 Thread.sleep(1000);
  1427.  
  1428.  
  1429.             } catch (InterruptedException e) {}            
  1430.  
  1431.  
  1432.         }
  1433.  
  1434.  
  1435.     }
  1436.  
  1437.  
  1438.  
  1439.  
  1440.  
  1441.     public void paint(Graphics g)
  1442.  
  1443.  
  1444.     {
  1445.  
  1446.  
  1447.         int i,x0,y0,x2,y2;
  1448.  
  1449.  
  1450.  
  1451.  
  1452.  
  1453.         if(images[BACKGROUND] == null){
  1454.  
  1455.  
  1456.             offScrGC.setColor(bgColor);
  1457.  
  1458.  
  1459.             offScrGC.fillRect(0,0,width,height);
  1460.  
  1461.  
  1462.         }
  1463.  
  1464.  
  1465.         else
  1466.  
  1467.  
  1468.             offScrGC.drawImage(images[BACKGROUND], 0, 0, this);
  1469.  
  1470.  
  1471.  
  1472.  
  1473.  
  1474.         offScrGC.setColor(caseColor);
  1475.  
  1476.  
  1477.  
  1478.  
  1479.  
  1480.         //Shrink one pixel so we don't clip anything off...
  1481.  
  1482.  
  1483.         offScrGC.fillOval(  originX+1,
  1484.  
  1485.  
  1486.                             originY+1,
  1487.  
  1488.  
  1489.                             minDimension-2,
  1490.  
  1491.  
  1492.                             minDimension-2);
  1493.  
  1494.  
  1495.         
  1496.  
  1497.  
  1498.         offScrGC.setColor(faceColor);
  1499.  
  1500.  
  1501.         offScrGC.fillOval(  originX + size(5),
  1502.  
  1503.  
  1504.                             originY + size(5),
  1505.  
  1506.  
  1507.                             minDimension - size(10),
  1508.  
  1509.  
  1510.                             minDimension - size(10));
  1511.  
  1512.  
  1513.                             
  1514.  
  1515.  
  1516.         offScrGC.setColor(trimColor);
  1517.  
  1518.  
  1519.         offScrGC.drawOval(  originX+1,
  1520.  
  1521.  
  1522.                             originY+1,
  1523.  
  1524.  
  1525.                             minDimension-2,
  1526.  
  1527.  
  1528.                             minDimension-2);
  1529.  
  1530.  
  1531.                             
  1532.  
  1533.  
  1534.         offScrGC.drawOval(  originX + size(5),
  1535.  
  1536.  
  1537.                             originY + size(5),
  1538.  
  1539.  
  1540.                             minDimension - size(10),
  1541.  
  1542.  
  1543.                             minDimension - size(10));
  1544.  
  1545.  
  1546.                             
  1547.  
  1548.  
  1549.         offScrGC.setColor(textColor);
  1550.  
  1551.  
  1552.  
  1553.  
  1554.  
  1555.         //Draw graduations, a longer index every fifth mark...
  1556.  
  1557.  
  1558.         for(i=0;i<60;i++){
  1559.  
  1560.  
  1561.             if(i==0 || (i>=5 && i%5 == 0)){
  1562.  
  1563.  
  1564.                 x0=(int)(x1+size(40)*Math.sin(MINSEC*i));
  1565.  
  1566.  
  1567.                 y0=(int)(y1+size(40)*Math.cos(MINSEC*i));
  1568.  
  1569.  
  1570.             }
  1571.  
  1572.  
  1573.             else{
  1574.  
  1575.  
  1576.                 x0=(int)(x1+size(42)*Math.sin(MINSEC*i));
  1577.  
  1578.  
  1579.                 y0=(int)(y1+size(42)*Math.cos(MINSEC*i));
  1580.  
  1581.  
  1582.             }
  1583.  
  1584.  
  1585.             x2=(int)(x1+size(44)*Math.sin(MINSEC*i));
  1586.  
  1587.  
  1588.             y2=(int)(y1+size(44)*Math.cos(MINSEC*i));
  1589.  
  1590.  
  1591.             offScrGC.drawLine(x0,y0,x2,y2);
  1592.  
  1593.  
  1594.         }
  1595.  
  1596.  
  1597.         
  1598.  
  1599.  
  1600.         drawHands(offScrGC);
  1601.  
  1602.  
  1603.         g.drawImage(offScrImage,0,0,this);
  1604.  
  1605.  
  1606.  
  1607.  
  1608.  
  1609.         isPainted=true;
  1610.  
  1611.  
  1612.     }
  1613.  
  1614.  
  1615.  
  1616.  
  1617.  
  1618.     public synchronized void update(Graphics g)
  1619.  
  1620.  
  1621.     {
  1622.  
  1623.  
  1624.         if(!isPainted)
  1625.  
  1626.  
  1627.             paint(g);
  1628.  
  1629.  
  1630.         else{
  1631.  
  1632.  
  1633.             drawHands(offScrGC);
  1634.  
  1635.  
  1636.             g.drawImage(offScrImage,0,0,this);
  1637.  
  1638.  
  1639.         }
  1640.  
  1641.  
  1642.     }
  1643.  
  1644.  
  1645. }
  1646.  
  1647.  
  1648.