Setting aside questions of style and encapsulation, I suspect the problem is related to where you're doing this in a class.
To instantiate the array in a method, you could do something like this:
class MyClass1 {
public void initImages(int width, int height) {
BufferedImage img1[] = new BufferedImage[60];
for (int i = 0; i < img1.length; i++) {
img1[i] = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
}
}
}
The array doesn't escape the method, so it will die there.
To instantiate the array as a static member, you could something like this:
class MyClass2 {
static int width = 100;
static int height = 100;
static BufferedImage img1[] = new BufferedImage[60];
static {
for (int i = 0; i < img1.length; i++) {
img1[i] = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
}
}
}
This uses a static initialization block.
...or this:
class MyClass3 {
static BufferedImage img1[] = initImages(100, 100);
public static BufferedImage[] initImages(int width, int height) {
BufferedImage img1[] = new BufferedImage[60];
for (int i = 0; i < img1.length; i++) {
img1[i] = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
}
return img1;
}
}
This uses a static method to initialize a static member.