I moved the keyPressed() to the main program, but now am getting error y variable does not exist.
Also, I’m not sure what below quote means…
Button [][] myButtons;
// Number of columns and rows in the grid
int num = 10;
int cols = num, rows = cols;
color background = color (random(255), random(255), random(255));
void setup() {
size(500, 500);
int x = (width/num)/2, y = x;
myButtons = new Button[cols][rows];
for (int i = 0; i < cols; i++) {
for (int j = 0; j < rows; j++) {
// Initialize each object
myButtons[i][j] = new Button (x+ i*(width/cols), y+ j*(height/rows),
color (random(255), random(255), random(255)), // random colors
color (random(255), random(255), random(255)), // new random colors when mouseOver
(width/num));
}
}
}
void draw() {
background(background);
for (int i = 0; i < cols; i++) {
for (int j = 0; j < rows; j++) {
myButtons[i][j].mouseOver();
myButtons[i][j].display();
}
}
}
void keyPressed() {
if (key == CODED) {
if (keyCode== UP) {
y = y+1;
} else if (keyCode== DOWN) {
y = y-1;
} else if (keyCode== LEFT) {
x = x-1;
} else if (keyCode== RIGHT) {
x = x+1;
}
}
}