randomsize 是我想传递给 Line 类中的显示函数的数组,每当我调用时p.display(randomsize[])
,我希望它会将值传递给display
函数。显然还有其他一些方法可以使这项工作,只是好奇为什么会发生错误?
ArrayList textlines;
int xpos=20;
int ypos=20;
int[]randomsize = new int[4];
void setup() {
size(1200, 768);
textlines = new ArrayList();
randomsize[0]=10;
randomsize[1]=15;
randomsize[2]=20;
randomsize[3]=25;
}
void draw() {
background(100, 100, 100);
for (int i=0; i<textlines.size(); i++) {
Line p=(Line)textlines.get(i);
p.display(randomsize[]);
}
}
void mousePressed() {
textlines.add(new Line(xpos, ypos, thistime));
}
class Line {
int x;
int y;
Line(int xpo, int ypo) {
x =xpo;
y =ypo;
}
void display(int therandom[]) {
fill(50, 50, 50);
rect(width/2, height/2, therandom[0], thatimee[0] );
rect(width/2, height/3, therandom[1], thatimee[1]);
}
}