?? clock.java
字號(hào):
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;
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -