Code:
//Import Elements
import java.awt.*;
import java.applet.Applet;
import java.awt.event.*;
import java.awt.Graphics;
import java.util.Date;

public class matchingSquares extends Applet implements MouseListener
{
	card[] cards;
	Image Cars;
	card firstcard, secondcard, blankcard;

	int pos;
	int gstatus;
	int tmp, x, y;
	int rows, cols;
	int width, height;
	int W = cols * width;
	int noGoes, noMatched;
	String status;
	String row, col;

	public void init()
	{
		// Add the MouseListener to your applet
  		addMouseListener(this);

		if (row == null)
			rows = 4;
		else

		if (rows > 4 || rows < 0)
			rows = 4;

		if (col == null)
			cols = 3;
		else

		if (cols > 3 || cols < 0)
			cols = 3;
		if (((rows %2) != 0) && ((cols %2) != 0))
			cols = 3;

		    width = 100;
      		height = 100;

		cards = new card[rows * cols];
		for(int i = 0, j = 0; i < rows * cols/2; i++, j+=2)
		{
			Cars = getImage(getDocumentBase(), "pic" +i+ ".jpg");
			cards[j] = new card(Cars, j+1, i+1);
         	cards[j+1] = new card(Cars, j+2, i+1);
		}
			firstcard = new card();
			secondcard = new card();
      		blankcard = new card();
	}

	public void paint(Graphics g)
	{
		g.clearRect(0, 0, W, 100);
		for (int i = 0; i < rows * cols; i++)
		{
			if (cards[i].getID() <= rows*cols/2)
		    {
		    	pos = cards[i].getPos();
		        g.setColor(Color.red);
		        g.fillRect(xPos(pos), yPos(pos), 100, 100);
		        g.setColor(Color.black);
		        g.drawRect(xPos(pos), yPos(pos), 100, 100);
		     }
		}

		if (firstcard.getID() != 0)
		{
			pos = firstcard.getPos();
		    g.drawImage(firstcard.getImg(), xPos(pos), yPos(pos), this);
		    g.drawRect(xPos(pos), yPos(pos), 100, 100);
		}

		if (secondcard.getID() != 0)
		{
			pos = secondcard.getPos();
		    g.drawImage(secondcard.getImg(), xPos(pos), yPos(pos), this);
		    g.drawRect(xPos(pos), yPos(pos), 100, 100);
      	}
	}

	public int xPos(int pos)
	{
		int col = cols;
		tmp = pos % col;

	    if (0 == tmp) tmp = col;
	    	y = (tmp - 1) * width;
	    return y;
	}

	public int yPos(int pos)
	{
		int col = cols;
		tmp = pos/col;

	    if (0 == pos%col) tmp = tmp - 1;
	    	y = (tmp * height) + 100;
	    return y;
	}

	public void mouseClicked(MouseEvent e)
	{
		x = e.getX();
		y = e.getY();
		repaint();
	}

	public boolean mouseClick(int x, int y)
	{
		if (y < 100)
	    {
	    	return true;
	    }

	    else if (cards[getmouseClick(x,y)].getID() > rows*cols/2)
	    	return true;

	    else if (0 == gstatus)
	    {
	    	firstcard = cards[getmouseClick(x,y)];
	        gstatus = 2;
	        status = "Choose Second Card";
	        repaint();
	        return true;
	    }

	    else if (1 == gstatus)
	    {
	    	firstcard = cards[getmouseClick(x,y)];
	        gstatus = 2;
	        status = "Choose Second Card";
	        repaint();
	        return true;
	    }

	    else if (2 == gstatus)
	    {
	    	if (firstcard == cards[getmouseClick(x,y)])
	    		return true;
	        	secondcard = cards[getmouseClick(x,y)];
	        	gstatus = 3;
	        	noGoes++;
	        if (firstcard.getID() == secondcard.getID())
	        {
	        	status = "Well Done";
	            noMatched++;
	          	if (rows*cols/2 == noMatched)
	            {
	           		status = "Game Over - YOU WIN";
	            }
	        }
	        else
	        	status = "Please Try Again";
	         	repaint();
	         	return true;
		}

	    else
	    	return false;
	}

	public int getmouseClick(int x, int y)
	{
		int row = (y-100)/height;
	    int col = x/width;
	    return (cols * row) + col;
	}


	public void mousePressed(MouseEvent e){}
	public void mouseEntered(MouseEvent e){}
	public void mouseReleased(MouseEvent e){}
	public void mouseExited(MouseEvent e){}
}
when i press the mouse it should show the image of a car but it stays as a red square and does not show the picture, can someone please help me.