关于j2me小程序问题 20

packageCanvas.Time;importjava.util.Calendar;importjava.util.TimeZone;importjava.util.... package Canvas.Time;

import java.util.Calendar;
import java.util.TimeZone;
import java.util.Timer;
import java.util.TimerTask;

import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.game.Sprite;

public class TimeCanvas extends Canvas {

private Image img = null;
private int widthOfNumber = 0;
private int heightOfNumber = 0;

private Timer timer = null;
private int hour = 0;
private int minute = 0;
private int second = 0;

public TimeCanvas(Image img) {
this.img = img;
widthOfNumber = img.getWidth() / 11;
heightOfNumber = img.getHeight();

timer = new Timer();
Task task = new Task();
timer.schedule(task, 0, 1000);
}

public void paint(Graphics g) {
g.setColor(255,255,255);
g.fillRect(0, 0, this.getWidth(), this.getHeight());

// hour
int num1 = hour /10;
int num2 = hour %10;

drawNumber(g, num1, 0);
drawNumber(g, num2, 1);

// maohao
drawNumber(g, 10, 2);

// minute
int num3 = minute / 10;
int num4 = minute % 10;
drawNumber(g, num3, 3);
drawNumber(g, num4, 4);

// maohao
drawNumber(g, 10, 5);

// second
int num5 = second / 10;
int num6 = second % 10;
drawNumber(g, num5, 6);
drawNumber(g, num6, 7);
}

public void drawNumber(Graphics g, int number, int location) {
g.drawRegion(img,
widthOfNumber*number, 0, widthOfNumber, heightOfNumber,
Sprite.TRANS_NONE,
widthOfNumber*location, 10,
Graphics.TOP | Graphics.LEFT);
}

class Task extends TimerTask {
public void run() {
TimeZone tz = TimeZone.getTimeZone("GMT+08:00"); // 获取时区

Calendar calendar = Calendar.getInstance(tz);
hour = calendar.get(Calendar.HOUR_OF_DAY);
minute = calendar.get(Calendar.MINUTE);
second = calendar.get(Calendar.SECOND);

repaint();
}
}
}

这段代码到底哪里出问题了 无法运行 如图
展开
 我来答
x358011055
2010-06-24 · TA获得超过253个赞
知道小有建树答主
回答量:234
采纳率:55%
帮助的人:166万
展开全部
你的模拟器没有配置好,好好检查一下你的模拟器的配置
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
huangshazsw
2010-07-01
知道答主
回答量:27
采纳率:0%
帮助的人:0
展开全部
要把运行的报错贴出来看看啊
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式