The Array setup is correct but the problem is you cannot declare the Array values there.
You could try this:
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class PictureDemo extends JFrame
{
// Create an ImageIcon Object
ImageIcon pic1 = new ImageIcon("background2.gif");
// Create a JLabel and display image
JLabel label1 = new JLabel(pic1);
JLabel label2 = new JLabel(pic1);
JLabel label3 = new JLabel(pic1);
JPanel pnl = new JPanel();
public static ImageIcon pic4 = new ImageIcon("7.gif");
public static ImageIcon[] images = new ImageIcon[3];
// Constructor
public PictureDemo()
{
super("Picture Display");
setSize(400,200);
setDefaultCloseOperation(EXIT_ON_CLOSE);
pnl.add(label1);
pnl.add(label2);
pnl.add(label3);
add(pnl);
setVisible(true);
}
public static void main(String[] args)
{
images[0] = pic4;
PictureDemo picdemo = new PictureDemo();
}
}
This compiles fine but obviousally pic4 isnt displayed yet in your code.