关于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();
}
}
}
这段代码到底哪里出问题了 无法运行 如图 展开
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();
}
}
}
这段代码到底哪里出问题了 无法运行 如图 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询