I get this error. 

                                 /*array dimension missing
                                new ImageIcon [] = getClass().getResource(name[0]),*/

and I dunno what's missing. and not sure if anything else is wrong because for now there are 4 erros for


    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.awt.Container;
    import java.io.IOException;
    import java.io.*;
    import java.awt.BorderLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.ImageIcon;
    import javax.swing.JButton;
    import javax.swing.JFrame;

    public class  exam extends JFrame

                public  static JComboBox imagesJComboBox ;
                public static JLabel label;

                private String[] name  = {"6.gif", "pikachu.gif", "kissplz.gif" , "mwah.gif"};
                private ImageIcon[] icons = {

                                    new ImageIcon [] = getClass().getResource(name[0]),
                                    new ImageIcon [] = getClass().getResource(name[1]),
                                    new ImageIcon [] = getClass().getResource(name[2]),
                                    new  ImageIcon [] = getClass().getResource(name[3])

        public exam()

            super ();
            setLayout(new FlowLayout());

        label = new JLabel(icons);
            imagesJComboBox =  new JComboBox ();
            imagesComboBox.addActionListener (new ActionListener());
            label.addActionListener(new ActionListener());

            add (imagesJComboBox);
            label = new JLabel (icons.index[0]);
            add (label);


    public void itemStateChange (ActionEvent e)

    if (e.getStateChange () == ActionEvent.SELECTED)
        label.setIcon(icons( imagesJComboBox.getSelectedIndexes()));


        public static void main(String [] args)
            { exam x = new exam();}

4 Years
Discussion Span
Last Post by JamesCherrill
 Your problem:new ImageIcon [] = getClass().getResource(name[0])
 What are u doing here...
 Solution: new ImageIcon(getClass().getResource(name[0]))
 Image Icon takes a parameter and that the image location.
 Hope this Help..

public void itemStateChange (ActionEvent e)

I think u require to implement ItemEvent, and please post the errors


You are reading images one ata time, but then trying to create a new array for each image. You can't assign an image to an array, just to one lement of the array, eg

 private ImageIcon[] icons = new ImageIcon[4];
 icons[0] =  getClass().getResource(name[0]);
 icons[1] =  getClass().getResource(name[1]);
 // etc (or use a loop)
This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.