006 低级界面的第一关----全屏

来源:互联网 发布:南京软件大道公司 编辑:程序博客网 时间:2024/05/02 01:40

-----汉字最好----http://blog.csdn.net/stgsd---

终于决定用canvas,很快碰到了一个问题---全屏.

 

public class LZform extends Canvas {

 

  public LZform() {
  setFullScreenMode(true);
  w=this.getWidth();
  h=this.getHeight();

.....

h居然不是应该的400而是390,那么在

protected void sizeChanged(int w, int h) {
  this.h=h;
  this.w=w;
 }

好像这样得到了正确的结果,实际上你根本无法立刻得到400,

原来sizeChanged是另一个线程不同步.

那就延时,-----结果是有时400有时390.

网上搜索了n多,没有一个稳当的.

该死的Graphics类明明有maxHeight偏偏设为私有.

 

单步调试:

protected void startApp() throws MIDletStateChangeException {
  u = new LZform();
  Display.getDisplay(this).setCurrent(u)

....

}

执行顺序如下

 startApp->LZform->回到startApp

->sizeChanged->sizeChanged  (晕调用了两次)

->paint.....

 

好吧,在paint中h是400了.

结论:所有需要全屏高度计算的量都需要在paint事件中计算.

 

原创粉丝点击