import javax.microedition.lcdui.Display;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
public class test extends MIDlet {
public a cv = new a();
public Display dis;
public a a=new a();
public Thread tr =new Thread(a);
public test() {
}
protected void startApp() throws MIDletStateChangeException {
tr.start();
dis = Display.getDisplay(this);
dis.setCurrent(cv);
cv.setFullScreenMode(true);
}
protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
}
protected void pauseApp() {
}
}
import java.util.Date;
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Graphics;
public class a extends Canvas implements Runnable {
String s = new Date().toString();
protected void paint(Graphics g) {
g.setColor(0, 0, 0);
g.fillRect(0, 0, this.getWidth(), this.getHeight());
g.setColor(255, 255, 255);
g
.drawString(s, this.getWidth() / 2, 0, Graphics.HCENTER
| Graphics.TOP);
}
public void run() {
while (true) {
s = new Date().toString();
repaint();
try {
Thread.currentThread().sleep(1000);
} catch (Exception ce) {
}
}
}
}
想达到的效果是在屏幕的上方显示时间,在模拟器上运行只显示开始的时间就不动了,为什么
还有,怎么单独得到年、月、日、星期、时、分、秒等等·······
谢谢
