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

📄 dgclock.java

📁 一个用JAVA编写的数字时钟源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
          }        int r=(colorval >> 16) & 0xff;        int g=(colorval >> 8) & 0xff;        int b=(colorval & 0xff);        newcolor=new Color(r,g,b);        colorCache.put(lowername,newcolor);                return (newcolor);    }    public void start()    {        if (timer == null)        {            timer=new Thread(this, "Dgclock");            timer.start();        }    }    public void run()    {        while (timer != null)        {            try            {               timer.sleep(1000);            }catch (InterruptedException e)             {                break;             }            repaint();        }        timer=null;    }        public void paintApplet()    {        int            i,            j,            k,            x;        Date            now=new Date();        int            hour,            minute,            second;        String            hr,            min,            sec,            today;        Graphics            gc;        if (TimeDiff != 0L)        {            now.setTime(now.getTime()+TimeDiff);        }        hr=formatDate(TimeFormat,now);        min=formatDate("%M",now);        sec=formatDate("%S",now);        if (ShowDate == true)        {            today=formatDate("%d",now);        }        else            today="";        if (tracker.statusID(0,true) == MediaTracker.COMPLETE)        {            //if (offset == 4)            if (use_frame == true)            {                gc=buf_image.getGraphics();                //draw the frame                gc.clipRect(0,0,base_width,base_height);                gc.drawImage(big_image,0,0,this);            }            //draw the hour digit images            for (i=0; i < hr.length(); i++)            {                gc=buf_image.getGraphics();                x=offset+(i*bdigit_width);                gc.clipRect(x,offset,15,20);                x=x-100-(hr.charAt(i)-'0')*bdigit_width;                gc.drawImage(big_image,x,offset,null);            }            // draw the colon image            gc=buf_image.getGraphics();            x=offset+i*bdigit_width;            gc.clipRect(x,offset,bdigit_width,bdigit_height);            x=x-250;            gc.drawImage(big_image,x,offset,null);            i++;            //draw the minute images            for (j=0; j < min.length(); j++)            {                gc=buf_image.getGraphics();                x=offset+(i*bdigit_width);                 gc.clipRect(x,offset,15,20);                x=x-100-(min.charAt(j)-'0')*bdigit_width;                gc.drawImage(big_image,x,offset,null);                i++;            }            // draw the second images            for (j=0; j < sec.length(); j++)            {                gc=buf_image.getGraphics();                x=offset+(i*bdigit_width)+(j*sdigit_width);                gc.clipRect(x,offset,sdigit_width,sdigit_height);                x=x-100-(sec.charAt(j)-'0')*sdigit_width;                gc.drawImage(big_image,x,offset-bdigit_height,null);            }            if (ShowDate == true)            {                for(k=0; k < today.length(); k++)                {                    gc=buf_image.getGraphics();                    x=offset+(i*bdigit_width)+(k*sdigit_width);                    gc.clipRect(x,offset+sdigit_height+1,                        sdigit_width,sdigit_height);                    x=x-100-(today.charAt(k)-'0')*sdigit_width;                    gc.drawImage(big_image,x,                        offset+sdigit_height-bdigit_height,null);                }            }        }    }    public void update(Graphics g)    {        if (tracker.statusID(0,true) == MediaTracker.COMPLETE)        {            if (buf_image != null)            {                if (use_frame == false)                {                    Graphics gc=buf_image.getGraphics();                    gc.setColor(bg_color);                    gc.fillRect(0,0,base_width,base_height);                }                paintApplet();                g.drawImage(buf_image,0,0,this);            }            else            {                g.clearRect(0,0,base_width,base_height);            }        }        else        {            g.drawString("Loading..",10,15);        }    }// Left Pad a number// taken from Clock2 by Per Reedtz Thomsen/Rachel Gollubprivate String padElement(int expr, char padChar){  String result = "";  // I'm just padding 2 digit numbers  if (expr < 10) result = result.concat(String.valueOf(padChar));  result = result.concat(String.valueOf(expr));  return(result);  }// Format a date according to the formatting string.// taken from Clock2 by Per Reedtz Thomsen/Rachel Gollubprivate String formatDate(String fmt, Date d){  String formattedDate = "";        // Retrieve the specific date information  int hour = d.getHours();  int minute = d.getMinutes();  int second = d.getSeconds();  int monthDay = d.getDate();          int US_Hour = hour < 13 ? hour : hour - 12;        // Loop through the format string  for(int i = 0; i < fmt.length(); i++)  {    if (fmt.charAt(i) == '%') // We've hit a formatting command...    {      i++; // Move past the '%' sign      // Figure out the format.      switch (fmt.charAt(i))      {      case 'H': // Hour -- 00 to 23        formattedDate = formattedDate.concat(padElement(hour, '0'));        break;      case 'I': // Hour -- 01 to 12        formattedDate = formattedDate.concat(padElement(US_Hour, '0'));        //formattedDate=formattedDate.concat(String.valueOf(US_Hour));        break;      case 'M': // Minutes -- 00 to 59        formattedDate = formattedDate.concat(padElement(minute, '0'));        break;      case 'd': // 2 digit month number        formattedDate = formattedDate.concat(padElement(monthDay, '0'));        break;      case 'S': // Second -- 00 to 61 (leap seconds)        formattedDate = formattedDate.concat(padElement(second, '0'));        break;      default:        formattedDate = formattedDate.concat("??");        break;      }    }    else // A regular character    {      formattedDate = formattedDate.concat(String.valueOf(fmt.charAt(i)));    }  } // end for  return(formattedDate);}    public void stop()    {        if (timer != null)        {           timer.stop();           timer=null;        }    }    public boolean handleEvent(Event evt)    {        switch(evt.id)        {            case Event.MOUSE_DOWN:            {                if (suspended)                {                    timer.resume();                }                else                {                    //Print ("Suspending..");                    timer.suspend();                }                suspended = !suspended;                break;            }                        case Event.MOUSE_MOVE:            {                if (tracker.statusID(0,true) != MediaTracker.COMPLETE)                {                    showStatus("Loading image...please wait!");                }                else                {                    if (suspended == false)                    {                        if (ShowStatus == true)                            showStatus("Dgclock 2.3 by ma_muquit@fccc.edu");                        else                        {                            String tz=getParameter("TZ");                            if (tz != null)                                showStatus(tz);                            else                                showStatus("your time");                        }                    }                }                break;            }        }        return true;    }    /*    public void Print(String str)    {        System.out.println(str);    }    */}// change a color of the imageclass ColorFilter extends RGBImageFilter{    Color        fgc,        bgc;    public ColorFilter(Color fg,Color bg)    {        fgc=fg;        bgc=bg;        canFilterIndexColorModel=true;    }    public int filterRGB(int x,int y,int rgb)    {                    int r=(rgb >> 16) & 0xff;        int g=(rgb >> 8) & 0xff;        int b=(rgb >> 0) & 0xff;        int fg_r=fgc.getRed();        int fg_g=fgc.getGreen();        int fg_b=fgc.getBlue();        int bg_r=bgc.getRed();        int bg_g=bgc.getGreen();        int bg_b=bgc.getBlue();        //System.out.println("bg r,g,b=" + bg_r + "," + bg_g + "," + bg_b);        //change foreground        if ((r == 0) && (g == 255) && (b == 255))        {            r=fg_r;            g=fg_g;            b=fg_b;            if ((r == 0) && (g == 0) && (b ==0))            {                r=g=b=1;            }            //System.out.println("fg r,g,b=" + r + "," + g + "," + b);        }        //change background        if ((r == 0) && (g == 0) && (b == 0))        {            r=bg_r;            g=bg_g;            b=bg_b;        }        return (rgb & 0xff000000) | (r << 16) | (g << 8) | (b << 0);    }}

⌨️ 快捷键说明

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