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

📄 clock.java

📁 J2ME上的一个播放器,可以更换皮肤.开源软件.
💻 JAVA
字号:
package inline.ui.ce;

import inline.ui.*;
import java.util.*;
import javax.microedition.lcdui.*;


    public class Clock extends AnimatedCanvasElement 
    {
	final private static int REPAINT_INTERVAL = 30000;
	final private static int REPAINT_INTERVAL_PRECISE = 1000;

	public final static int TYPE_SIMPLE = 1;
	public final static int TYPE_BIG = 2;
	
	private int type;
	private boolean precise;
	private int margin;
	private String time;
	private int xyproportions;
	
        public Clock(HostCanvas prnt, int x, int y, int w, int h)
	{
	    super(prnt, x, y, w,h);

	    setPrecise(false);
	    setType(TYPE_SIMPLE);
	    setStyleable(true);
	    onAnimate();
	}

	public Clock(HostCanvas prnt)
	{
	    this(prnt, 0, 0, 0, 0);
	}
	
	public void onAnimate()
	{
	    Calendar cal = Calendar.getInstance();
	    int hour = cal.get(Calendar.HOUR_OF_DAY);
	    int minute = cal.get(Calendar.MINUTE);
	    
	    String th = Integer.toString(hour);
	    if (th.length()==1) th = "0" + th;
	    
	    String tm = Integer.toString(minute);
	    if (tm.length()==1) tm = "0" + tm;

	    time = th + ":" + tm;

	    if (precise)
	    {
		String ts = Integer.toString(cal.get(Calendar.SECOND));
		if (ts.length()==1) ts = "0" + ts;
		
		time += ":" + ts;
	    }
	    
	    repaint();
	}
	
	public void paintElement(Graphics g) 
        {
            synchronized (g) 
            {
		if (type == TYPE_SIMPLE)
		{
		    paintSimpleClock(g);
		}
		else if (type == TYPE_BIG)
		{
		    paintBigClock(g);
		}
            }
        }
	
	private void paintSimpleClock(Graphics g)
	{
	    g.drawString(time, getWidth()>>1, 0, Graphics.TOP|Graphics.HCENTER);
	}
	
	private void paintBigClock(Graphics g)
	{
	    int precadd = 0;
	    if (precise) precadd = 5;
	    int clwidth = getWidth()-(margin<<1);
	    int xsth = 16*(clwidth)/(9+precadd);
	    int chrw = xsth<<1;
	    
	    int hei = getHeight();
	    int yoff = 0;
	    if (xyproportions>0)
	    {
		hei = clwidth*xyproportions/100;
		if (hei>getHeight()) hei = getHeight();
		yoff = (getHeight()-hei)>>1;
	    }
	    int xpos = 0;

	    for(int i=0;i<time.length();i++)
	    {
		int cc = (int)time.charAt(i);
		if (cc>=0x30 && cc<=0x39)
		{
		    cc = cc - 0x30 + FIGURE_DIGIT0;
		    execMetaCommands(g,cc,margin+(xpos>>4),yoff,chrw>>4,hei);
		    xpos = xpos+chrw;
		}
		else if (cc == (int)':')
		{
		    execMetaCommands(g,FIGURE_COLON_HALF,margin+(xpos>>4),yoff,chrw>>4,hei);
		    xpos = xpos+xsth;
		}
	    }
	}
	
	public void setType(int ttype)
	{
	    type = ttype;
	}
	
	public void setMargin(int mmargin)
	{
	    margin = mmargin;
	}
	
	public void setProportions(int pprop)
	{
	    xyproportions = pprop;
	}
	
	public void setPrecise(boolean pprecise)
	{
	    precise = pprecise;

	    int timeinterval = REPAINT_INTERVAL;
	    if (precise) timeinterval = REPAINT_INTERVAL_PRECISE;
	    
	    setAnimated(true);
	    setInterval(timeinterval);
	}
	
	protected int getContentHeightImpl()
	{
	    int res = getFontHeight();
	    if (type == TYPE_BIG) res = 0;
	    return res;
	}

    }



⌨️ 快捷键说明

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