当前位置: 代码迷 >> J2ME >> ~帮帮忙,改天请喝茶,该怎么处理
  详细解决方案

~帮帮忙,改天请喝茶,该怎么处理

热度:6952   发布时间:2013-02-25 21:37:34.0
~~~~帮帮忙,改天请喝茶
public   class   mainCanvas   extends   Canvas{

int   width=getWidth();
int   height=getHeight();

}

我要在非继承Canvas类中调用
width和height的值
要怎么调用
给出具体代码

------解决方案--------------------------------------------------------
public class mainCanvas extends Canvas{

public static int width=getWidth();
public state int height=getHeight();

}


public class otherClass extends MIDlet
{
public void startApp(){
System.out.println(mainCanvas.width);
}
public void pauseApp(){}
public void destroyApp(boolean bl){
}
}
------解决方案--------------------------------------------------------
//#if "ScreenSize " == "240x320 "
int width = 240;
int height = 320;
//#else
//#int width = 176;
//#int height = 208;
//#endif

用polish编译
------解决方案--------------------------------------------------------
class Canvas{

private int width = 1;
private int height = 2;

public int getWidth(){

return width;
}
public int getHeight(){

return height;
}




}

class mainCanvas extends Canvas{

int width=getWidth();
int height=getHeight();

}

public class Test {

public static void main(String[] args) {
mainCanvas a = new mainCanvas();

System.out.println( "width: "+a.width + " height: "+a.height);
}

}
  相关解决方案