Why am I getting the error :java:16: error: illegal start of type
for(int i = 0; i < 9; i++){
I have checked old labs and this is the correct usage of it I thought.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class Lab3Panel extends JPanel {
Lab3Panel() {
setLayout(new GridLayout(3,3));
}
Lab3Label label[] = new Lab3Label[9];
for (int i = 0; i < 9; i++) {
label[i] = new Lab3Label();
add(label[i]);
}
// ...
}
The for loop needs to be in a method, a constructor, or at a bare minimum, between a pair of
{}brackets. But probably a constructor.