⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dgclock.java

📁 一个用JAVA编写的数字时钟源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
import java.applet.*;import java.awt.*;import java.awt.image.*;import java.util.Hashtable;import java.util.*;//////////////////////////////////////////////////////////// Description: a simple digital clock in Java (1.0.2 applet)// Author: Muhammad A Muquit// email:  ma_muquit@fccc.edu// URL:    http://www.fccc.edu/users/muquit/Dgclock.html//// 12/05/1995           lets play with Java// 01/29/96             some clean up// 02/13/96             added ornamental frame//                      added 24 hr time format (TimeFormat)// 02/15/96             GMT+-hhmm to display time of any place (TZ)//                      date (ShowDate)// 03/13/96             using MediaTrcaker to stop incremental display//                      Suggested by Jim Graham// 03/16/96             display clock without frame.//                      shows version info while mouse is moved on the appl.//                      stop clock by clicking mouse// 10/29/1996           jdk 1.1 on DEC OSF1 found a syntax error// 11/02/1996           Version 2.2// 11/02/1996           uses an image strip instead of individual digit images//                      loads much faster.// 11/05/1996           Version 2.3//                      change fg & bg color on the fly//// Copyright:// This program is in the public domain. Do anything you like with it.// It would be nice if you give me credit for it tho.///////////////////////////////////////////////////////////*Example of calling convention:The default 24 hr format:<applet code="Dgclock.class" width=100 height=30></applet>To display time in 12 hr format:<applet code="Dgclock.class" width=100 height=30><param name="TimeFormat" value="%I"></applet>To display NewYork time:<applet code="Dgclock.class" width=100 height=30><param name="TZ" value="GMT-0500"></applet>12 or 24 hr format<param name="TimeFormat" value="%H">    (24 hr format - default)<param name="TimeFormat" value="%I">    (12 hr format)the format for value is GMT+-hhmm, for example<param name="TZ" value="GMT+0600">    (6 hours west of Greenwich meridian)<param name="TZ" value="GMT+0430">    (4 hours, 30 minutes                                      west of Greenwich meridian)<param name="TZ" value="GMT+0000">    (Greenwich)<param name="TZ" value="GMT-0500">    (5 hours east of Greenwich meridian)<param name="ShowDate" value="yes">   (show date with time)<param name="ShowDate" value="no">   (don't show date - default)<applet code="Dgclock.class" width=89 height=20><param name="ShowFrame" value="no">   (do not wrap clock with frame)<param name="ShowVersion" value="no"> (do not show version info when the                                       mouse cursor is moved on the applet)<param name="fg" value="color">       (change foreground color, color can be                                       any of red,green,blue,cyan,magenta,                                       yellow,orange,pink,black,white or                                        a 6 digit hex number like ff0000)<param name="bg" value="color">       (change background color)*/public class Dgclock extends Applet implements Runnable{    MediaTracker        tracker;    Thread        timer=null;    boolean        suspended=false;    Image        big_image,        buf_image;    int        bdigit_width=15;    int        bdigit_height=20;    int        sdigit_width=7;    int        sdigit_height=9;    int        base_width=100;    int        base_height=30;    int        offset=4;    String        TimeFormat="%H";    long        TimeDiff=0L;    boolean        ShowDate=false;    boolean        ShowStatus=true;    boolean        use_frame=true;    Color        bg_color=Color.black;        /**         * Cache of colors indexed by name or color-spec.         */        static Hashtable colorCache = new Hashtable();                /**         * Initialize the color hash table.         */        static        {            colorCache.put("red", Color.red);            colorCache.put("green", Color.green);            colorCache.put("blue", Color.blue);            colorCache.put("cyan", Color.cyan);            colorCache.put("magenta", Color.magenta);            colorCache.put("yellow", Color.yellow);            colorCache.put("orange", Color.orange);            colorCache.put("pink", Color.pink);            colorCache.put("white", Color.white);            colorCache.put("black", Color.black);        }                 int checkTZ(String TZ)    {       int          d;       int            hr,            min;                        int               counter=0;       int diff=0;             hr=0;       min=0;       if (TZ != null)       {             int length=TZ.length();            if (length == 8)            {                //Print("Length= " + length);                int c=TZ.charAt(3);                if ((c == '-') || (c == '+'))                {                    String tzval=TZ.substring(4,8);                    //Print("TZ value= " + tzval);                                 for (int i=0; i < tzval.length(); i++)                    {                        d=tzval.charAt(i);                                 if ( (d >= '0') && d <= '9')                        {                            if (counter < 2)                                  hr=hr*10+(d-'0');                            else                                  min=min*10+(d-'0');                            counter++;                        }                    }                    //Print("Hour: " + hr + " Min: " + min);                    diff=(hr*60)+min;                    if (c == '-')                        diff=(-diff);                }            }       }       return diff;    }      public void init()    {        int            x,            y;        Image            rgb_image=null;        String            fg,            bg;        fg=bg=null;        // check if TimeFormat is supplied        TimeFormat=getParameter("TimeFormat");        if (TimeFormat != null)        {            if  ((!TimeFormat.equals("%I")) && (!TimeFormat.equals("%H")))                TimeFormat="%H";        }        else            TimeFormat="%H";        String gp=getParameter("ShowDate");        if (gp != null)        {            if (gp.equals("yes"))                ShowDate=true;        }        gp=getParameter("ShowVersion");        if (gp != null)        {            if (gp.equals("no"))                ShowStatus=false;        }        // check if frame need to be displayed        gp=getParameter("ShowFrame");        if (gp != null)        {            if (gp.equals("no"))            {                use_frame=false;                /*                offset=0;                base_width=89;                base_height=20;                */            }        }             // check if fg and bg parameters are supplied        fg=getParameter("fg");        bg=getParameter("bg");        //Print("TImeForamt= " + TimeFormat);        tracker=new MediaTracker(this);        try        {        // load the big image            if ((fg == null) && (bg == null))            {                //Print("fg and bg null");                big_image=getImage(getCodeBase(),"./dgstrip.gif");                tracker.addImage(big_image,0);            }            else            {                rgb_image=getImage(getCodeBase(),"./dgstrip.gif");                tracker.addImage(rgb_image,0);            }        } catch (Exception e) {;}        if ((fg != null) || (bg != null))        {            //Print ("fg or bg is not null");            Color                fgc,                bgc;            if (fg != null)                fgc=lookupColor(true,fg);            else                fgc=Color.cyan;            if (bg != null)                bgc=lookupColor(false,bg);            else                bgc=Color.black;            bg_color=bgc;            ImageFilter f=new ColorFilter(fgc,bgc);            ImageProducer producer=new FilteredImageSource(                rgb_image.getSource(),f);            big_image=this.createImage(producer);        }        // check for TZ        int            diff=0;        String timezone=getParameter("TZ");        if (timezone != null)        {            if (timezone.equals("LOCAL"))                TimeDiff=0L;            else            {                Date date=new Date();                diff=checkTZ(timezone);                TimeDiff=((long) date.getTimezoneOffset())*60000+diff*60000;            }        }        try        {            buf_image=createImage(base_width,base_height);        } catch (Exception e) {;}   //jdk 1.1 on osf found a problem    }        /**     * taken from AlphaBullet applet by Jim Graham     */    private synchronized Color lookupColor(boolean bb,String colorname)    {        /**         * boolean bb is true when looking color for foreground         * we need this flag, so if color lookup fails, we can choose         * contrasting colors for fg and bg         */        String lowername=colorname.toLowerCase();        Color newcolor=(Color) colorCache.get(lowername);        if (newcolor != null)            return newcolor;        int colorval;               try        {            colorval=Integer.parseInt(lowername,16);        } catch (NumberFormatException e)          {            if (bb == true)                return (Color.cyan);            else                return (Color.black);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -