0 0

java me 画图问题5

问题在注释中,求教各位大侠
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;


import java.util.Timer;
import java.util.Random;
import java.util.TimerTask;
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Graphics;

public class MIDlet1 extends MIDlet {
private MyCanvas mc = new MyCanvas();
private Display dis;
//private Graphics oo;
public MIDlet1() {
// TODO Auto-generated constructor stub

}

protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
// TODO Auto-generated method stub

}

protected void pauseApp() {
// TODO Auto-generated method stub

}

protected void startApp() throws MIDletStateChangeException {
// TODO Auto-generated method stub
dis = Display.getDisplay(this);
dis.setCurrent(mc);
mc.setTitle("MyCanvas");
Timer timer = new Timer();
    timer.schedule(new Task(),8000,1000);
}

class Task extends TimerTask
{

Random rnd = new Random();
MyCanvas a= new MyCanvas();
   public void run()
{
//检验是否执行timer.schedule(new Task(), 0, 1000);
System.out.println("#####");
mc.repaint();
//这个方法有效
//a.repaint();      这个方法无效           为什么?     
}
}
    //以下为画图
    class MyCanvas extends Canvas
{  
public void paint(Graphics g)
{
Random rnd = new Random();
g.setColor(rnd.nextInt(255), rnd.nextInt(255), rnd.nextInt(255));
//这个g,fillArc函数每次都会画两个圆,为何啊?我在另一个MIDlet中又是正常的,只画一次
g.fillArc(rnd.nextInt(this.getWidth()),rnd.nextInt(this.getHeight()),
rnd.nextInt(120),rnd.nextInt(120), 0, 360);

}
}
    }
2011年9月24日 11:01
目前还没有答案

相关推荐

Global site tag (gtag.js) - Google Analytics