i have problem when i am trying to run this code......can anyone solve this problem....its about memory matching game.....
here is the code i am trying to work with...
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.net.URL;
import java.applet.*;
import java.util.Random;
public class Memory extends JFrame
{
static JLabel guessLabel = new JLabel ();
static JLabel label0 = new JLabel ();
static JLabel label1 = new JLabel ();
static JLabel label2 = new JLabel ();
static JLabel label3 = new JLabel ();
static JLabel label4 = new JLabel ();
static JLabel label5 = new JLabel ();
static JLabel label6 = new JLabel ();
static JLabel label7 = new JLabel ();
static JLabel label8 = new JLabel ();
static JLabel label9 = new JLabel ();
static JLabel label10 = new JLabel ();
static JLabel label11 = new JLabel ();
static JLabel label12 = new JLabel ();
static JLabel label13 = new JLabel ();
static JLabel label14 = new JLabel ();
static JLabel label15 = new JLabel ();
static JLabel[] boxlabel = new JLabel [16];
static ImageIcon apple = new ImageIcon ("apple.gif");
static ImageIcon bannana = new ImageIcon ("bannana.gif");
static ImageIcon cherry = new ImageIcon ("cherry.gif");
static ImageIcon grape = new ImageIcon ("grape.gif");
static ImageIcon orange = new ImageIcon ("orange.gif");
static ImageIcon lemon = new ImageIcon ("lemon.gif");
static ImageIcon plum = new ImageIcon ("plum.gif");
static ImageIcon pear = new ImageIcon ("apple.pear");
static ImageIcon backing = new ImageIcon ("backing.gif");
static ImageIcon apple = new ImageIcon ("apple.gif");
static ImageIcon[] choiceIcon = new ImageIcon [8];
static JButton newButton =new JButton();
static JButton exitButton = new JButton();
static Random myRandom = new Random();
static int choice ;
static int index;
static int [] picked =new int [2] ;
static int [] behind = new int [16];
static int guesses ;
static int remaining ;
static AudioClip matchsound ;
static AudioClip noMatchSound;
static Timer delayTimer ;
public static void main (String args[])
{
new Memory().show(); //create frame
try //getsounds
{
matchsound =Applet.newAudioClip (new URL("file:" + "aaa.wav"));
noMatchSound =Applet.newAudioClip(new URL("file" +"abc.wav"));
}
catch (Exception ex)
{
}
newButton.doclick();
}
public Memory()
{
setTitle ("Memory game");
getContentPane().setBackground(Color BLUE);
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent evt )
{
exitForm(evt);
}
});
getContentPane().setLayout(new GridLayout ());
GridBagConstraints gridConstraints = new GridBagConstraints();
guessLabel.setText("Guesses : 0");
guessLabel.setForeground(Color .WHITE);
guessLabel.setFont(new Font ("Arial",Font.BOLD,18));
gridConstraints.gridx =1;
gridConstraints.gridy =0;
gridConstraints.gridwidth =2;
gridConstraints.insets =new Insets(10,10,10,18);
getContentPane().add(guessLabel.gridConstraints);
boxLabel[0]=label0;
boxLabel[1]=label1;
boxLabel[2]=label2;
boxLabel[3]=label3;
boxLabel[4]=label4;
boxLabel[5]=label5;
boxLabel[6]=label6;
boxLabel[7]=label7;
boxLabel[8]=label8;
boxLabel[9]=label9;
boxLabel[10]=label10;
boxLabel[11]=label11;
boxLabel[12]=label12;
boxLabel[13]=label13;
boxLabel[14]=label14;
boxLabel[15]=label15;
int x=0;
int y=1;
for (i=0;i<16;i++)
{
gridConstraints= new GridBagConstraints();
boxLabel[i].setPreferredSize(new Dimension (70,70));
boxLabel[i].setIcon(backing);
gridConstraints.gridx = x;
gridConstraints.gridy = y;
gridConstraints.insets = new Insets(5,5,5,5);
getContentPane().add(boxLabel[i].gridConstraints);
boxLabel[i].addMouseListener(new MouseAdapter()
{
public void mouseClicked(MouseEvent e)
{
labelMouseClicked(e);
}
});
x++;
if (x==3)
{
x=0;
y+=1;
}
}
newButton.setText("New Game");
gridConstraints =new GridBagConstraints();
gridConstraints.gridx = 1;
gridConstraints.gridy = 6;
gridConstraints.gridwidth = 2;
gridConstraints.insets = new Insets(10,10,10,10);
getContentPane().add(newbutton.gridConstraints);
newButton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
newButtonActionPerformed(e);
}
});
exitButton.setText("Exit");
gridConstraints= new GridBagConstraints();
gridConstraints.gridx=1;
gridConstraints.gridy=7;
gridConstraints.gridwidth=2;
gridConstraints.insets= new Insets (0,10,10,10);
getContentPane().add(exitButton.gridConstraints);
exitButton.addActionListener(new ActionListener()
{
public void actionperformed (ActionEvent e)
{
exitButtonActionPerformed(e);
}
});
delayTimer = new Timer (1.new ActionListener()
{
delayTimerActionPerfirmed(e) ;
});
pack();
Dimension screenSize = Toolkit. getDefaultToolkit().getScreenSize();
setBounds((int)(0.5*(screenSize.width-getWidth())).(int)(0.5*(screenSize.x-getX())).(int(0.5)*(screenSize.y-getY()))
choiceIcon[1]= apple;
choiceIcon[2]= bannana;
choiceIcon[3]= cherry;
choiceIcon[4]= grape;
choiceIcon[5]= orange;
choiceIcon[6]= pear;
choiceIcon[7]= plum;
}
private void labelMouseClicked(MouseEvent e)
{
Component clickedComponent =e.getComponent();
for (index=0;index<16;i++)
{
if (clickedComponent == boxLabel[index])
{
break;
}
}
if ((choice == 1 && index==picked[0])||behind[index==-1|| newButton])
{
return;
}
boxLabel[index].setIcon(choiceIcon[behind[index]]);
if (choice==0)
{
picked[0]=index;
choice =1;
return ;
}
delayTimer.start ();
}
private void newButtonActionPerformed(ActionEvent e)
{
guesses = 0;
remaining = 8;
guessLabel.setText("Guesses :0");
behind = sortIntegers(16);
for(int i=0;i<16;i++)
{
boxLabel[i].setIcon(backing);
if (behind[i]>7)
{
behind[i]=behind [i]-8;
}
}
choice =0 ;
newButton.setEnabled(false);
exitButton.setText("Stop" );
}
private void exitButtonActionPerformed(ActionEvent e)
{
if (exitButton. getText().equals ("Exit"))
{
exitform (null);
}
else
{
exitButton.setText("Exit");
newButton.setEnable(true);
}
}
private void exitForm(WindowEvent evt)
{
System.exit(0);
}
private void delayTimerActionPerformed(ActionEvent e)
{
delayTimer.stop();
guesses ++;
guessLabel.setText("Guesses"+String.value of (guesses));
Picked[i]=index;
if (behind[picked[0]]==behind[picked[i]])
{
matchSound.play();
behind[picked[0]]=-1;
behind[picked[1]]=-1;
remaining--;
}
else
{
noMatchSound.play();
long t=System .currentTimeMillis();
do {} while (System.currentTimeMillis()-t<1000);
boxLabel[picked[0]].setIcon(backing);
boxLabel[picked[1]].setIcon(backing);
}
choice =0 ;
if (remaining ==0)
{
exitButton.doClick();
newButton.requestFocus();
}
}
private static int[] sortIntegers(int n)
{
int nArray[]=new int [n];
int temp,s;
Random myRandom = new Random ();
for (int i=0;i<n;i++)
{
nArray[i]=i;
}
for (int i=0;i>=1;i--)
{
s = myRandom.nextInt(i);
temp = nArray[s];
nArray [s] = nArray[i-1];
nArray[i-1] = temp;
}
return (nArray);
}
}

