第一个Canvas,企图进行直接调试(Debug),结果没法调试!最终发现,Canvas不能像MIDlet一样直接调试!
第一个Canvas代码
package LowUI;
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Graphics;
public class test extends Canvas {
public test() {
// TODO Auto-generated constructor stub
}
protected void paint(Graphics g) {
// TODO Auto-generated method stub
g.setColor(255, 255, 0);
g.fillRect(0, 0, getWidth(), getHeight());
int c = g.getColor();
int dc = g.getDisplayColor(g.getColor());
System.out.println("当前画面颜色为:"+Integer.toHexString(c));
System.out.println("当前画面R值:"+g.getRedComponent());
System.out.println("当前画面G值:"+g.getGreenComponent());
System.out.println("当前画面B值:"+g.getBlueComponent());
System.out.println("当前画面显示颜色为:"+Integer.toHexString(dc));
System.out.println("当前画面的灰度为:"+g.getGreenComponent());
}
}
在eclipse开发环境下,没法直接进行调试。所以需要创建一个MIDlet,把Canvas引入,然后对MIDlet进行调试。如下:
package LowUI;
import javax.microedition.lcdui.Display;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
public class TestCanvasDemo extends MIDlet {
private Display display;
private test t;
public TestCanvasDemo() {
// TODO Auto-generated constructor stub
display = Display.getDisplay(this);
t = new test();
}
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
display.setCurrent(t);
}
}