我正在尝试将 thistime[] 传递给类并使用它来定义两个矩形的宽度和高度。这只是我的初始代码的简化版本,我在令牌“]”上得到了错误语法错误,在这个令牌之后应该是 VariableDeclaratorld ,这是我的代码:
ArrayList textlines;
int xpos=20;
int ypos=20;
int[]thistime = new int[2];
void setup() {
size(1200, 768);
textlines = new ArrayList();
thistime[0] =3;
thistime[1] =30;
}
void draw() {
}
void mousePressed() {
textlines.add(new Line(xpos, ypos,thistime));
for (int i=0; i<textlines.size(); i++) {
Line p=(Line)textlines.get(i);
p.display();
}
}
class Line {
int x;
int y;
int thatimee[];
Line(int xpo, int ypo, int thetimee[]) {
x =xpo;
y =ypo;
thatimee[]= new int[thetimee.length];
thatimee[0]=thetimee[0];
thatimee[1]=thetimee[1];
}
void display() {
fill(50, 50, 50);
rect(random(width), random(height), thatimee[0],thatimee[0] );
rect(random(width), random(height), thatimee[1], thatimee[1]);
}
}
错误在行
thatimee[]= new int[thetimee.length];
谁知道原因?