日期:2014-05-20  浏览次数:20717 次

~~~~帮帮忙,改天请喝茶
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);
}

}