Home | Resume | Decimal Time | Clean Transportation | XR | Alpha Telephone


Back to Dime page.

// © 2001-2003, Sergey Zaytsev, All Rights Reserved

 

import java.applet.*;

import java.awt.*;

import java.util.*;

 

// 1 day = 86,400 regular seconds = 100,000 digital seconds (deconds)

// 864 regular milliseconds = 1000 digital milliseconds (millideconds)

 

public class TimerClass extends Applet

    implements Runnable

{

   

          Thread timer;

          int Mode = 1;         // 1 - regular time, 2 - digital time

          int SleepMS;  // sleep milliseconds

          int y;

          int x;

 

    public void init()

          {

                   String strMode = getParameter("MODE");

                   if (strMode != null)

                             Mode = Integer.parseInt(strMode);

                  

                   SleepMS = (Mode == 1) ? 1000 : 864;

 

                   String strBackGround = getParameter("background");

                   if (strBackGround != null)

                             this.setBackground(stringToColor(strBackGround));

 

                   String strForeGround = getParameter("foreground");

                   if (strForeGround != null)

                             this.setForeground(stringToColor(strForeGround));

 

                   String strFontName = getParameter("FONTNAME");

                   if (strFontName == null)

                             strFontName = this.getFont().getName();

 

                   int intFontSize = this.getFont().getSize();

                   String strFontSize = getParameter("FONTSIZE");

                   if (strFontSize != null)

                             intFontSize = Integer.parseInt(strFontSize);

 

                   int intFontStyle = this.getFont().getStyle();

                   String strFontStyle = getParameter("FONTSTYLE");

                   if (strFontStyle != null)

                             intFontStyle = Integer.parseInt(strFontStyle);

 

                   // Set font             

                   this.setFont(new Font(strFontName, intFontStyle, intFontSize));

                  

                   y = this.size().height / 2 + intFontSize / 2;

 

                   FontMetrics fm = getFontMetrics(this.getFont());

 

                   x = this.size().width / 2 - fm.stringWidth((Mode == 1) ? "00:00:00 AM" : "00:00:00") / 2;

          }

 

    public void paint(Graphics screen)

          {

                   Calendar now = Calendar.getInstance();

                   int intHour = now.get(Calendar.HOUR);

                   int intHourOfDay = now.get(Calendar.HOUR_OF_DAY);

                   int intAM_PM = now.get(Calendar.AM_PM);

                   int intMinute = now.get(Calendar.MINUTE);

                   int intSecond = now.get(Calendar.SECOND);

                   String strShow;

                            

                   if (Mode == 1)

                             strShow = FormatTime(intHour, intMinute, intSecond, intAM_PM);

                   else

                   {

                             int intMilliSecond = now.get(Calendar.MILLISECOND);

 

                             int intMilliSecondOfDay = ((intHourOfDay * 60 + intMinute) * 60 + intSecond) * 1000 +

                                                                                        intMilliSecond;

                             int intDecondOfDay = intMilliSecondOfDay / 864;

                  

                             int intDour = intDecondOfDay / 10000;

                             int intDinute = (intDecondOfDay - (intDour * 10000)) / 100;

                             int intDecond = intDecondOfDay % 100;

 

                             strShow = FormatDime(intDour, intDinute, intDecond);

                   }

 

                   screen.drawString(strShow, x, y);

    }

 

    public void start()

          {

        if (timer == null)

                   {

            timer = new Thread(this);

            timer.start();

        }

    }

 

    public void run()

          {

        while (true)

                   {

            repaint();

            try { Thread.sleep(SleepMS); }

            catch (InterruptedException e) { }

        }

    }

 

    public void stop()

          {

        if (timer != null)

                   {

            timer.stop();

            timer = null;

        }

    }

 

    public String FormatTime(int intHour, int intMinute, int intSecond, int intAM_PM)

          {

                   if ((intHour == 0) && (intAM_PM == 1) /* PM */)

                             intHour = 12;

                   String strTime = "";

                   if (intHour < 10)

                             strTime = "0";

                   strTime += intHour + ":";

                   if (intMinute < 10)

                             strTime += "0";

                   strTime += intMinute + ":";

                   if (intSecond < 10)

                             strTime += "0";

                   strTime += intSecond + " " + ((intAM_PM == 0) ? "AM" : "PM");

                  

                   return strTime;

    }

 

          public String FormatDime(int intDour, int intDinute, int intDecond)

          {

                   String strDime = "0" + intDour + ".";

                   if (intDinute < 10)

                             strDime += "0";

                   strDime += intDinute + ".";

                   if (intDecond < 10)

                             strDime += "0";

                   strDime += intDecond;

                  

                   return strDime;

    }

 

          // Converts a string formatted as "rrggbb" to an awt.Color object

          private Color stringToColor(String paramValue)

          {

                   return new Color(Integer.decode("0x" + paramValue).intValue());

          }

 

          // External interface used by design tools to show properties of an applet.

          public String[][] getParameterInfo()

          {

                   String[][] info =

                   {

                             { "background", "String", "Background color, format \"rrggbb\"" },

                             { "foreground", "String", "Foreground color, format \"rrggbb\"" },

                             { "fontname", "String", "Font Name" },

                             { "fontsize", "int", "Font Size" },

                             { "fontstyle", "int", "Font Style" },

                             { "mode", "int", "1 - Regular Time; 2 - Decimal Time" }

                   };

                   return info;

          }

         

}

Back to Dime page.


 
Web serg.us

Home | Resume | Decimal Time | Clean Transportation | XR | Alpha Telephone

U.S. Patents of the day:    4117253    4581871    5630468    5126076    6508802    5470725   

U.S. Patents grouped by 10:    559840x    674379x    651615x    609227x    542802x    579715x   

U.S. Trademarks of the day:    2544477    2436760    2471136    2728085    2395756    2020936   

U.S. Trademark Applications:    74164272    74805002    78966490    77918490    77690603    75677425   

Sample Terms:    Astigmatism    Camera    Chlorine    Color    Comforter    Deco    Diamond   
                    Earrings    Fluoroscope    Formula    Knife    Laptop    Sapphire    Wife

You are 50626 visitor on this page since November 1, 2003