【发布时间】:2011-11-14 06:47:50
【问题描述】:
我有以下方法
public void multiArrayGrid(){
GRect[][] rect = new GRect[3][3];
int rWidth = 50;
int rHeight = 50;
for (int i=0; i<3; i++) {
for (int j=0; j<3; j++) {
rect[i][i] = new GRect(50,50);
add(rect[i][i], rWidth+50, rHeight+50);
rWidth+=50;
}
rHeight+=50;
rWidth = 50;
}
}
上面的方法实际上是做一个3x3的矩形网格。
如何访问,例如,rect[0][0]?
【问题讨论】:
-
您想在代码中的什么位置访问 rect[0][0]?
-
dope,我没有将 rect 声明为实例变量,并试图从另一种方法访问它。谢谢 你能告诉我如何让 mouseEvents 在 rect[i][i] 上工作吗?谢谢
-
@user750993 您需要为您的 GRect 实例添加一个鼠标侦听器,在本例中为
rect[i][i]。