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

📄 billsclock.java

📁 大家好
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
            tzDifference = Double.valueOf(paramString).doubleValue();

       paramString  =   getParameter( "LOCALONLY" );
        if( paramString != null && Integer.valueOf(paramString).intValue() != 0){
                localOnly=true;
                tzDifference=0.;
        }

        paramString    = getParameter( "BGCOLOR");
        if( paramString != null )
            bgColor=parseColorString(paramString);

        paramString    = getParameter( "FACECOLOR");
        if( paramString != null )
            faceColor=parseColorString(paramString);

        paramString    = getParameter( "SWEEPCOLOR");
        if( paramString != null )
            sweepColor=parseColorString(paramString);

        paramString    = getParameter( "MINUTECOLOR");
        if( paramString != null )
            minuteColor=parseColorString(paramString);

        paramString    = getParameter( "HOURCOLOR");
        if( paramString != null )
            hourColor=parseColorString(paramString);

        paramString    = getParameter( "TEXTCOLOR");
        if( paramString != null )
            textColor=parseColorString(paramString);

        paramString    = getParameter( "CASECOLOR");
        if( paramString != null )
            caseColor=parseColorString(paramString);

        paramString    = getParameter( "TRIMCOLOR");
        if( paramString != null )
            trimColor=parseColorString(paramString);

        logoString  = getParameter( "LOGOSTRING");
        if( logoString == null )
            logoString=JAVEX;
        else if(logoString.length() > 8)
            logoString= logoString.substring(0,8); //Max 8 characters!

        szImagesURL[BACKGROUND]  = getParameter("BGIMAGEURL");
        szImagesURL[LOGO] = getParameter("LOGOIMAGEURL");

        for(int i=0; i<2; i++){
            if(szImagesURL[i] != null){
                try{
                    imagesURL[i]=new URL(getCodeBase(),szImagesURL[i]);
                } catch (MalformedURLException e)
                    {
                        showURLerror(e);
                        imagesURL[i]=null;
                        images[i]=null;
                    }
                if(imagesURL[i] != null){
                    showStatus("Javex loading image: " + imagesURL[i].toString());
                    images[i]=getImage(imagesURL[i]);
                    if(images[i] != null)
                        tracker.addImage(images[i],i);
                    showStatus("");
                }
                if(images[i] != null)
                    try{
                        tracker.waitForID(i);
                    }catch (InterruptedException e)
                        {
                            images[i]=null;
                        }
            }
            else images[i]=null;
        }

        cur_time=(localOnly)? new hms() : new hms(tzDifference);
        lastHour=-1.0;
        lastMinute=-1;
        lastSecond=-1;

        x1=width/2;
        y1=height/2;

        minDimension= Math.min(width, height);
        originX=(width-minDimension)/2;
        originY=(height-minDimension)/2;

        xPoints[1]=x1-size(3); xPoints[2]=x1+size(3); xPoints[0]=x1;
        yPoints[1]=y1-size(38);yPoints[2]=y1-size(38); yPoints[0]=y1-size(27);

        sweep=new sweepHand(x1,y1,size(40),3);
        minuteHand=new hmHand(x1,y1,size(40),size(6),6);
        hourHand=new hmHand(x1,y1,size(25),size(8),6);

        font=new Font("TXT",Font.BOLD,size(10));

        offScrImage = createImage(width,height);
        offScrGC = offScrImage.getGraphics();

        System.out.println(getAppletInfo());
    }

    public void start()
    {
        if(clockThread == null){
            clockThread = new Thread(this);
            clockThread.start();
        }
    }

    public void stop()
    {
        if(null != clockThread){
            clockThread.stop();
            clockThread=null;
        }
    }

    private void drawHands(Graphics g)
    {

        double angle;
        int i,j;
        int x,y;

        angle=MINSEC * lastSecond;
        sweep.draw(faceColor, angle, g);

        if(cur_time.getMinutes() != lastMinute){
            minuteHand.draw(faceColor,MINSEC*lastMinute,g);
            if(cur_time.get_hours() != lastHour)
                hourHand.draw(faceColor,HOUR*lastHour,g);
        }

        g.setColor(textColor);
        g.fillRect(originX+size(12),y1-size(2),size(10),size(4));
        g.fillRect(x1-size(2),originY + minDimension-size(22),size(4),size(10));
        g.fillPolygon( xPoints, yPoints, 3);
        for(i=1;i<12;i+=3)
            for(j=i;j<i+2;j++){
                x=(int)(x1+Math.sin(HOUR*j)*size(35));
                y=(int)(y1-Math.cos(HOUR*j)*size(35));
                g.fillOval(x-size(3),y-size(3),size(6),size(6));
            }

        //Set the font and get font info...
        g.setFont(font);
        FontMetrics fm=g.getFontMetrics();

        //Paint our logo...
        g.drawString(logoString,x1-fm.stringWidth(logoString)/2,y1-size(12));

        //Get the day of the month...
        String day=Integer.toString(cur_time.getDate(),10);

        //Paint it...
        g.drawString(   day,
                        originX + minDimension-size(14)-fm.stringWidth(day),
                        y1+size(5));

        //and put a box around it.
        g.drawRect( originX + minDimension-size(14)-fm.stringWidth(day)-size(2),
                    y1-size(5)-size(2),
                    fm.stringWidth(day)+size(4),
                    size(10)+size(4));

        if(images[LOGO] != null){
            x = originX + (minDimension-images[LOGO].getWidth(this))/2;
            y = y1 + (minDimension/2 - size(22) - images[LOGO].getHeight(this))/2;
            if(x > 0 && y > 0)
                offScrGC.drawImage(images[LOGO], x, y, this);
        }

        lastHour=cur_time.get_hours();
        hourHand.draw(hourColor,HOUR*lastHour,g);

        lastMinute=cur_time.getMinutes();
        minuteHand.draw(minuteColor,MINSEC*lastMinute,g);

        g.setColor(minuteColor);
        g.fillOval(x1-size(4),y1-size(4),size(8),size(8));
        g.setColor(sweepColor);
        g.fillOval(x1-size(3),y1-size(3),size(6),size(6));

        lastSecond=cur_time.getSeconds();
        angle=MINSEC*lastSecond;
        sweep.draw(sweepColor, angle,g);

        g.setColor(trimColor);
        g.fillOval(x1-size(1),y1-size(1),size(2),size(2));
    }

    private Color parseColorString(String colorString)
    {
        if(colorString.length()==6){
            int R = Integer.valueOf(colorString.substring(0,2),16).intValue();
            int G = Integer.valueOf(colorString.substring(2,4),16).intValue();
            int B = Integer.valueOf(colorString.substring(4,6),16).intValue();
            return new Color(R,G,B);
        }
        else return Color.lightGray;
    }

    public void run()
    {
        //Let's not hog the system, now...
        Thread.currentThread().setPriority(Thread.MIN_PRIORITY);

        repaint();
        while(null != clockThread){
            cur_time= (localOnly)? new hms() :new hms(tzDifference);
            repaint();

            try{
                Thread.sleep(1000);
            } catch (InterruptedException e) {}
        }
        System.exit(0);
    }

    public void paint(Graphics g)
    {
        int i,x0,y0,x2,y2;

        if(images[BACKGROUND] == null){
            offScrGC.setColor(bgColor);
            offScrGC.fillRect(0,0,width,height);
        }
        else
            offScrGC.drawImage(images[BACKGROUND], 0, 0, this);

        offScrGC.setColor(caseColor);

        //Shrink one pixel so we don't clip anything off...
        offScrGC.fillOval(  originX+1,
                            originY+1,
                            minDimension-2,
                            minDimension-2);

        offScrGC.setColor(faceColor);
        offScrGC.fillOval(  originX + size(5),
                            originY + size(5),
                            minDimension - size(10),
                            minDimension - size(10));

        offScrGC.setColor(trimColor);
        offScrGC.drawOval(  originX+1,
                            originY+1,
                            minDimension-2,
                            minDimension-2);

        offScrGC.drawOval(  originX + size(5),
                            originY + size(5),
                            minDimension - size(10),
                            minDimension - size(10));

        offScrGC.setColor(textColor);

        //Draw graduations, a longer index every fifth mark...
        for(i=0;i<60;i++){
            if(i==0 || (i>=5 && i%5 == 0)){
                x0=(int)(x1+size(40)*Math.sin(MINSEC*i));
                y0=(int)(y1+size(40)*Math.cos(MINSEC*i));
            }
            else{
                x0=(int)(x1+size(42)*Math.sin(MINSEC*i));
                y0=(int)(y1+size(42)*Math.cos(MINSEC*i));
            }
            x2=(int)(x1+size(44)*Math.sin(MINSEC*i));
            y2=(int)(y1+size(44)*Math.cos(MINSEC*i));
            offScrGC.drawLine(x0,y0,x2,y2);
        }

        drawHands(offScrGC);
        g.drawImage(offScrImage,0,0,this);

        isPainted=true;
    }

    public synchronized void update(Graphics g)
    {
        if(!isPainted)
            paint(g);
        else{
            drawHands(offScrGC);
            g.drawImage(offScrImage,0,0,this);
        }
    }
}

⌨️ 快捷键说明

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