Thursday, December 22, 2011

C Program for check the String is plaindrom or not.......

/* Plaindrom String */

#include<stdio.h>
#include<conio.h>
#include<string.h>

void main()
{
 char str1[10],str2[10],i,l;
 clrscr();
 printf("Eneter the string:");
 gets(str1);

  l=strlen(str1);
  l--;

  i=0;

  while(l>=0)
  {
   str2[i]=str1[l];
   l--;
   i++;
   }
   str2[i]='\0';
   i=strcmp(str1,str2);

   if(i==0)
    printf("\nString is plaindrom");
   else
    printf("\nString is not plaindrom");

   getch();

}

C Program for Factorial useing Recursion....

#include<stdio.h>
#include<conio.h>
long int fact(long int);
 void main()
 { 
   long int  num,f;
   clrscr();
   printf("Input a number: ");
   scanf("%ld",&num);
   f=fact(num);
   printf("\nFactorial is %ld",f);
   getch();
 }
 long int fact(long int n)
 {
    if(n==0)
         return 1;
    else 
             return(n*fact(n-1)); 
 }

C Program for Bubble Sort.....

/************************Bubble Sorting**************************/

 #include<stdio.h> 
 #include<conio.h> 
  
  void main() 
   { 

       int a[100],n,i,j,t;
      clrscr(); 
      printf("\n\n Enter integer value for total no.s of elements to be sorted: "); 
       scanf("%d",&n); 
  
      for( i=0;i<=n-1;i++) 
                   scanf("%d",&a[i]); 
   for(i=n-2;i>=0;i--) 
          { 
             for(j=0;j<=i;j++) 
  
                   { 
                     if(a[j]>a[j+1]) 
                                     { 
                                       t=a[j]; 
                                      a[j]=a[j+1]; 
                                      a[j+1]=t; 
                                     } 
                    } 
            }          
        printf("\n\n Finally sorted array is: "); 
        for( i=0;i<=n-1;i++) 
    printf("\n%d",a[i]);
    getch();
  
   }

C Program for find the armstrong no with in range..

#include<stdio.h>
#include<conio.h>
#include<dos.h>
void main()
{
 int no,num,arm=0;
 int i,rev=0;
 clrscr();
 for(i=1;i<=500;i++)
{
 num=no=i;
 arm=0;
 rev=0;
 while(no!=0)
    {
     arm=no%10;
     no=no/10;
     rev=rev+(arm*arm*arm);
    }
  if(num==rev)
    printf("\nArmsrtrong no : %d",num);
}
getch();

}

Saturday, December 17, 2011

C Program for Multiplaction of two Matrix...

#include<stdio.h>
#include<conio.h>

void main()
{
    int m1[10][10],i,j,k,m2[10][10],add[10][10],mult[10][10],r1,c1,r2,c2;
    printf("Enter number of rows and columns of first matrix MAX 10\n");
    scanf("%d%d",&r1,&c1);
    printf("Enter number of rows and columns of second matrix MAX 10\n");
    scanf("%d%d",&r2,&c2);
    if(r2==c1)
    {
        printf("Enter rows and columns of First matrix \n");
        printf("Row wise\n");
        for(i=0;i<r1;i++)
        {
            for(j=0;j<c1;j++)
                scanf("%d",&m1[i][j]);
        }
        printf("You have entered the first matrix as follows:\n");
        for(i=0;i<r1;i++)
        {
            for(j=0;j<c1;j++)
                printf("%d\t",m1[i][j]);
            printf("\n");
        }
        printf("Enter rows and columns of Second matrix \n");
        printf("Again row wise\n");
        for(i=0;i<r2;i++)
        {
            for(j=0;j<c2;j++)
                scanf("%d",&m2[i][j]);
        }
        printf("You have entered the second matrix as follows:\n");
        for(i=0;i<r2;i++)
        {
            for(j=0;j<c2;j++)
                printf("%d\t",m2[i][j]);
            printf("\n");
        }
        if(r1==r2&&c1==c2)
        {
            printf("Now we add both the above matrix \n");
            printf("The result of the addition is as follows;\n");
            for(i=0;i<r1;i++)
            {
                for(j=0;j<c1;j++)
                {
                    add[i][j]=m1[i][j]+m2[i][j];
                    printf("%d\t",add[i][j]);
                }
                printf("\n");
            }
        }
        else
        {
            printf("Addition cannot be done as rows or columns are not equal\n");
        }
        printf("Now we multiply both the above matrix \n");
        printf("The result of the multiplication is as follows:\n");
       
        for(i=0;i<r1;i++)
        {
            for(j=0;j<c2;j++)
            {
                mult[i][j]=0;
                for(k=0;k<r1;k++)
                {
                    mult[i][j]+=m1[i][k]*m2[k][j];
                    /*mult[0][0]=m1[0][0]*m2[0][0]+m1[0][1]*m2[1][0]+m1[0][2]*m2[2][0];*/
                }
                printf("%d\t",mult[i][j]);
            }
            printf("\n");
        }
        getch();
    }
    else
    {
        printf("Matrix multiplication cannot be done");
    }
}

C Program for find a Prime Number...

#include<stdio.h>
#include<conio.h>

void main()
{
int i,j=2,ch=0;
clrscr();
       printf("\nENTER ANY NUMBER: ");
       scanf("%d",&i);
  while(j<=i/2)
       {
    if(i%j==0)
      {
            printf("%d IS NOT PRIME",i);
            ch=1;
            break;
          }
        else
          {
           j++;
          }
      }
 if(ch==0)
   {
   printf("%d IS PRIME",i);
   }
   getch();

}

C Program for Binary Search....

/* binary Search*/

#include<conio.h>
#include<stdio.h>
int main()
{
  int a[10],i,n,m,c=0,l,u,mid;

  printf("Enter the size of an array->");
  scanf("%d",&n);

  printf("\nEnter the elements of the array in sorted order->");
  for(i=0;i<n;i++)
      scanf("%d",&a[i]);
 
  printf("\nThe elements of an array are->");
  for(i=0;i<n;i++)
      printf(" %d",a[i]);
 
  printf("\nEnter the number to be search->");
  scanf("%d",&m);
 
l=0,u=n-1;

  while(l<=u)
    {
      mid=(l+u)/2;
      if(m==a[mid])
    {
          c=1;
              break;
          }
      else if(m<a[mid])
    {
              u=mid-1;
        }
      else
          l=mid+1;
   }

  if(c==0)
      printf("\nThe number is not in the list");
  else
      printf("\nThe number is found at %d",mid+1);
  getch();
}

C Program for Sum of Matrix .......

#include<stdio.h>
#include<conio.h>
void main()
{
 int a[3][3],b[3][3],c[3][3],i,j,k,sum=0;
 clrscr();
 printf("Enter the element of 1st 3*3 matrix:");
  for(i=0;i<3;i++)
     for(j=0;j<3;j++)
    scanf("%d",&a[i][j]);

 printf("Enter the element of 2nd 3*3 matrix:");
  for(i=0;i<3;i++)
     for(j=0;j<3;j++)
    scanf("%d",&b[i][j]);

  for(i=0;i<3;i++)
    {   
     for(j=0;j<3;j++)
    {
         c[i][j]=a[i][j]+b[i][j];
    }
     }   


printf("\n1st Matrix is :\n");
  for(i=0;i<3;i++)
   {   
     for(j=0;j<3;j++)
      {
    printf("\t%d",a[i][j]);
      }
    printf("\n");
    }

printf("\n2nd Matrix is :\n");
  for(i=0;i<3;i++)
   {   
     for(j=0;j<3;j++)
      {
    printf("\t%d",b[i][j]);
      }
    printf("\n");
    }
printf("\nOutput Matrix is :\n");
  for(i=0;i<3;i++)
   {   
     for(j=0;j<3;j++)
      {
    printf("\t%d",c[i][j]);
      }
    printf("\n");
    }
getch();

}

C program for find the minimum and maximum value in an array...

/* find the min and max value with these locations*/
#include<stdio.h>
#include<conio.h>
void main()
{
 int a[20],i, n,max,min,min_pos,max_pos;
 clrscr();
 printf("Enter the Limit:");
 scanf("%d",&n);

 if(n<=20)
    {
        printf("Enter The No for Array:");
        for(i=0;i<n;i++)
            scanf("%d",&a[i]);
   
        max=a[0];
        min=a[0];
        for(i=0;i<n;i++)
            {
                if(a[i]>=max)
                    {
                        max=a[i];
                        max_pos=i+1;
                    }
                if(a[i]<=min)
                    {
                        min=a[i];
                        min_pos=i+1;
                    }

            }   
        printf("\nThe Bigest number in array is %d at %d",max,max_pos);
        printf("\nThe Smallest number in array is %d at %d",min,mix_pos);
       
    }
   else
    printf("Enter the value of less than or equal to 20");

 getch();
       
}

C Program for find the Greatest Number in an array...

#include<stdio.h>
#include<conio.h>
void main()
{
 int a[20],i, n,max;
 clrscr();
 printf("Enter the Limit:");
 scanf("%d",&n);

 if(n<=20)
    {
        printf("Enter The No for Array:");
        for(i=0;i<n;i++)
            scanf("%d",&a[i]);
   
        max=a[0];
        for(i=0;i<n;i++)
            {
                if(a[i]>=max)
                    max=a[i];
            }   
        printf("\nThe Bigest number in array is %d",max);
       
    }
   else
    printf("Enter the value of less than or equal to 20");

 getch();
       
}

Wednesday, November 30, 2011

program of Calculator in java


/**********************Calculator in java AWT******************************/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

class Calculator implements ActionListener,WindowListener
{

        String data= "0",opr;
  int number, first_number, result;

       
 Frame f;
 Button b[]=new Button [10];
 Button b1[]= new Button [6];

 TextField tf;
 
 Calculator()
 {
   f= new Frame("Calculator");
   tf= new TextField("");

   for(int i=0;i<10;i++)
    {
  String str= Integer.toString(i);
b[i]= new Button(str);
     }
 
   b1[0]= new Button("+");
   b1[1]= new Button("-");
   b1[2]= new Button("*");
   b1[3]= new Button("/");
   b1[4]= new Button("C");
   b1[5]= new Button("=");

 
 }

 void display()
 {

  try{
  int left,top, hight,width;
   left=20;
   top=80;
   hight=30;
   width=30;

 f.setLayout(null);
//  f.setSize(220,250);
 f.setBounds(350,250,220,250);
  f.setVisible(true);



  for(int i=1;i<10;i++)
{
     
      b[i].setBounds(left,top,width,hight);

if(i%3==0)
{
top=top+40;
left= 20;
}
       
else
left=left+40;
             
    }


b[0].setBounds(left+40,top,width,hight);
   
b1[0].setBounds(left+120,80,width*2,hight);
b1[1].setBounds(left+120,120,width*2,hight);
b1[2].setBounds(left+120,160,width*2,hight);
b1[3].setBounds(left+120,200,width*2,hight);
b1[4].setBounds(left,200,width,hight);
b1[5].setBounds(left+80,200,width,hight);


tf.setBounds(left,40,180,hight);

for(int i=0;i<10;i++)
  f.add(b[i]);

for(int i=0;i<6;i++)
  f.add(b1[i]);


f.add(tf);


for(int i=0;i<10;i++)
b[i].addActionListener(this);

for(int i=0;i<6;i++)
b1[i].addActionListener(this);
f.addWindowListener(this);
  }
 catch(Exception e)
{
System.out.println(e);
}
 }


/**************************************Window Listener Interface************************/

public void windowActivated(WindowEvent e)
{}
public void windowClosed(WindowEvent e)
{}
public void windowClosing(WindowEvent e)
{

System.exit(1);

}
public void windowDeactivated(WindowEvent e)
{}
public void windowDeiconified(WindowEvent e)
{}
public void windowIconified(WindowEvent e)
{}
public void windowOpened(WindowEvent e)
{}





public void actionPerformed(ActionEvent e)
{


try{

if(e.getSource()==b[0])        
{
number=(number*10)+0;
data=Integer.toString(number);
tf.setText(data);

}
else if(e.getSource()==b[1])        
{
number=(number*10)+1;
data=Integer.toString(number);
tf.setText(data);

}
else if(e.getSource()==b[2])        
{
number=(number*10)+2;
data=Integer.toString(number);
tf.setText(data);

}

else if(e.getSource()==b[3])        
{
number=(number*10)+3;
data=Integer.toString(number);
tf.setText(data);

}

else if(e.getSource()==b[4])        
{
number=(number*10)+4;
data=Integer.toString(number);
tf.setText(data);

}

else if(e.getSource()==b[5])        
{
number=(number*10)+5;
data=Integer.toString(number);
tf.setText(data);

}

else if(e.getSource()==b[6])        
{
number=(number*10)+6;
data=Integer.toString(number);
tf.setText(data);

}
else if(e.getSource()==b[7])        
{
number=(number*10)+7;
data=Integer.toString(number);
tf.setText(data);

}
else if(e.getSource()==b[8])        
{
number=(number*10)+8;
data=Integer.toString(number);
tf.setText(data);

}

else if(e.getSource()==b[9])        
{
number=(number*10)+9;
data=Integer.toString(number);
tf.setText(data);

}
else if(e.getSource()==b1[4])
{

}


/**************************************************************************/
if(e.getSource()==b1[0])
{
opr="+";
first_number=number;
number=0;
}
else if(e.getSource()==b1[1])
{
opr="-";
first_number=number;
number=0;
}
else if(e.getSource()==b1[2])
{
opr="*";
first_number=number;
number=0;
}
else if(e.getSource()==b1[3])
{
opr="/";
first_number=number;
number=0;
}
else if(e.getSource()==b1[4])
{
opr=" ";
number=0;
first_number=0;
result=0;
tf.setText(" ");
}
else if(e.getSource()==b1[5])
{
if(opr.equals("+"))
{
result=number+first_number;
data=Integer.toString(result);
tf.setText(data);
number=result;
result=first_number;
}

else if(opr.equals("-"))
{
result=number-first_number;
data=Integer.toString(result);
tf.setText(data);
number=result;
result=first_number;
}
else if(opr.equals("*"))
{
result=number*first_number;
data=Integer.toString(result);
tf.setText(data);
number=result;
result=first_number;
}

else if(opr.equals("/"))
{
result=number+first_number;
data=Integer.toString(result);
tf.setText(data);
first_number=result;
result=number;
}
}


   }
catch(Exception ex)
{
System.out.println(ex);
}

}


}

//****************************************************************************

class CalculatorTest
{
 public static void main(String args[])
 {
 Calculator c= new Calculator();
 c.display();
 }
}

/***************************Pic of Calculator*****************************************/


/******************Download the Zip file of above program********************************/
Download the Zip file of Calculator


Thursday, November 24, 2011

few Fun Movements.....

enjoy the Life Cycle of Love heeee heee


Paint brush program in java Applet

hi ...
this is a applet class of Paint brush...
u can download it .......
**************************snap shot of running program*********************************

you can download the zip file of above program
Download the zip file of Paint Brush


Wednesday, November 23, 2011

Snake And Ladders Game Code in java


Snake and Ladder game code in java.

import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.net.*;
import java.io.*;

class Main implements ActionListener,MouseListener
{
 JFrame f;
 JTabbedPane tabPane;
 JPanel mainPanel,introPanel,gamePanel,playerPassPanel,diePanel; 
 JPanel gameCenter,gameEast,gameWest,gameNorth,gameSouth;
 Icon p1,p2,header;
 Icon up,down;
 Icon icon[][]= new Icon[10][10];
 Icon winericon[][]= new Icon[10][10];
 Icon dieIcon;
 JButton introB[]= new JButton[5];
 JButton b[][]=new JButton[10][10];
 JButton start,restart;
 JButton JBplayer,JBcomputer;  
JLabel die;
Random randomNo;
 int imageFlag;
 int i,j,num;
 int prevIp1,prevJp1;
 int path;
 int p1value,p2value;
 int player,computer;
 int gameover;
 int cimageFlag=0;
 int cnoFlag=0;
 String str;
  int n[][]={ { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9},
{10,11,12,13,14,15,16,17,18,19},
{20,21,22,23,24,25,26,27,28,29},
{30,31,32,33,34,35,36,37,38,39},
{40,41,42,43,44,45,46,47,48,49},
{50,51,52,53,54,55,56,57,58,59},
{60,61,62,63,64,65,66,67,68,69},
{70,71,72,73,74,75,76,77,78,79},
{80,81,82,83,84,85,86,87,88,89},
{90,91,92,93,94,95,96,97,98,99},
 };

 int game[][]={
      {100,99,98,97,96,95,94,93,92,91},
       {81,82,83,84,85,86,87,88,89,90},
{80,79,78,77,76,75,74,73,72,71},
{61,62,63,64,65,66,67,68,69,70},
{60,59,58,57,56,55,54,53,52,51},
{41,42,43,44,45,46,47,48,49,50},
{40,39,38,37,36,35,34,33,32,31},
{21,22,23,24,25,26,27,28,29,30},
{20,19,18,17,16,15,14,13,12,11},
{ 1, 2, 3, 4, 5, 6, 7, 8, 9,10},
     };
int winer[][]={
{ 1, 2, 3, 4, 5, 6, 7, 8, 9,10},
{11,12,13,14,15,16,17,18,19,20},
{21,22,23,24,25,26,27,28,29,30},
{31,32,33,34,35,36,37,38,39,40},
{41,42,43,44,45,46,47,48,49,50},
{51,52,53,54,55,56,57,58,59,60},
{61,62,63,64,65,66,67,68,69,70},
{71,72,73,74,75,76,77,78,79,80},
{81,82,83,84,85,86,87,88,89,90},
{91,92,93,94,95,96,97,98,99,100},
     };
 Main()
 {

 f= new JFrame("Snakes and Ladders 1.0");
 f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

 mainPanel= new JPanel();
 tabPane =new JTabbedPane(JTabbedPane.LEFT);
 f.setLayout(new BorderLayout());
 for(int i=0;i<introB.length;i++)
  {
introB[i]= new JButton(Integer.toString(i));
}

 randomNo= new Random();

 JBplayer= new JButton("player1");
 JBcomputer= new JButton("player2");

 JBplayer.setEnabled(false);
 JBcomputer.setEnabled(false);

 JBplayer.addActionListener(this);
 JBcomputer.addActionListener(this); 
 die = new JLabel();
game();
introduction();
 f.add(tabPane,BorderLayout.CENTER);
 f.setResizable(false);
   f.setSize(750,700);
 //f.pack();
  f.setVisible(true);
  }

void introduction()
{

 introPanel= new JPanel();
  
 JPanel main= new JPanel();
 JLabel l1= new JLabel();
 //JPanel about= new JPanel(); 
  
       
 JLabel l2=new JLabel("<html><body><Font color='red' Size='14'> Hi,</Font><Font color='green' Size='4'>every one this is Snake and Ladders version 1.0 , plz mail if u find any type of problem/error and ur sugession.<br></Font> <Font color='red' Size='3'>thank you visit for more Programs:</Font>  <Font color='gray' Size='6'>gauravsiwach.blogspot.com</Font> </body></html>");


 Icon mypic;

 mypic=new ImageIcon("images/itsme.jpg");         

 l1.setIcon(mypic);

 introPanel.setLayout(new BorderLayout()); 
 introPanel.add(l1,BorderLayout.CENTER); 
 l2.addMouseListener(this);
 l2.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
 introPanel.add(l2,BorderLayout.SOUTH); 
 tabPane.addTab("About me",introPanel);
}

void game()
{
 JLabel gameheader= new JLabel();
 JLabel logo = new JLabel(); 
 JLabel l1= new JLabel(); 
 JLabel l2= new JLabel(); 

 restart= new JButton("Restart");
 restart.setEnabled(false);
 restart.addActionListener(this);

 start= new JButton("Start");
 start.addActionListener(this);

 gamePanel= new JPanel();


 gameCenter=new JPanel();
 gameWest= new JPanel();
 gameNorth=new JPanel();
 gameSouth= new JPanel();

  gameCenter.setLayout(new GridLayout(10,10));
  gameEast= new JPanel(new GridLayout(2,1));

  gameWest.setLayout(new FlowLayout());
 gameNorth=new JPanel(new FlowLayout());
 gameSouth= new JPanel(new FlowLayout());

 gamePanel.setLayout(new BorderLayout());

 p1= new ImageIcon("images/p1.gif");        
 p2= new ImageIcon("images/p2.gif");       
 up= new ImageIcon("images/up.gif");
 down= new ImageIcon("images/down.gif");

 l1.setIcon(p1);
 l2.setIcon(p2);

 header=new ImageIcon("images/header.jpg");        
 gameheader.setIcon(header);
  
  for(int i=0;i<10;i++)
for(int j=0;j<10;j++)
{
b[i][j]= new JButton();
        //b[i][j].addActionListener(this);        
path=game[i][j];
str=Integer.toString(path);
icon[i][j]=new ImageIcon("images/"+str+".jpg");
       b[i][j].setIcon(icon[i][j]);
                 
}

for(int i=0;i<10;i++)
for(int j=0;j<10;j++)
{
path=winer[i][j];
str=Integer.toString(path);
winericon[i][j]=new ImageIcon("images/winer/"+str+".jpg");
                        // b[i][j].setIcon(winericon[i][j]);
}
 str=Integer.toString(1);
 dieIcon= new ImageIcon("images/Game dies/"+str+".jpg");
 die.setIcon(dieIcon);
 gameSouth.add(l1); 
 gameSouth.add(JBplayer);
 gameSouth.add(die);
 gameSouth.add(JBcomputer); 
 gameSouth.add(l2); 

 gameNorth.add(start);
 gameNorth.add(gameheader);
 gameNorth.add(restart);
  
  for(int i=0;i<10;i++)
{
for(int j=0;j<10;j++)
{
gameCenter.add(b[i][j]);

              //System.out.print("["+i+"]["+j+"],");
                
}
//System.out.println();
}
 gamePanel.add(gameCenter,BorderLayout.CENTER);
 gamePanel.add(gameWest,BorderLayout.WEST);
 gamePanel.add(gameNorth,BorderLayout.NORTH);
 gamePanel.add(gameSouth,BorderLayout.SOUTH);

  tabPane.addTab("Game",gamePanel);
  
}

void chance()
{
 int n=randomNo.nextInt(3);
 int i=0;

 //System.out.println("Chacne is :"+n) ;
 if(n==0)
chance();

 if(n==1)
{
player=1;
computer=0;
}
  else if(n==2)
{
player=0;
  computer=1;
}

  if(n==1)
{
JBcomputer.setEnabled(false);
JBplayer.setEnabled(true);
    
}
 else if(n==2)
{
JBcomputer.setEnabled(true);
JBplayer.setEnabled(false);
    
  }
}

public void actionPerformed(ActionEvent e)
{

 int n=0;
try{
 if(e.getSource()==JBplayer)
{

  //System.out.println("JB Player");
do{
n =playerPassNumber();
}while(n==0);

//System.out.println("UR playerPass value is :"+n);        
p1value=p1value+n;
         
if(p1value>=100)
{
p1value=100;
}
 
playerimageTraval(p1value);

JBcomputer.setEnabled(true);
JBplayer.setEnabled(false);
setBothImage();
  }
  else if(e.getSource()==JBcomputer)
{
//System.out.println("JB Computer");
do{
n =playerPassNumber();
}while(n==0);

//System.out.println("Computer Pass Value is "+n);
p2value=p2value+n;
if(p2value>=100)
{
p2value=100;
}
computerimageTraval(p2value);
JBcomputer.setEnabled(false);
JBplayer.setEnabled(true);

setBothImage();
}
  else if(e.getSource()==restart)
{
  p1value=0;
p2value=0;

cnoFlag=0;
cimageFlag=0;

chance();
rePrint();
}
  else if(e.getSource()==start)
{
gameover=0;
p1value=0;
p2value=0;
cnoFlag=0;
cimageFlag=0;
rePrint();
 start.setEnabled(false);
 restart.setEnabled(true);
 chance();
}
else
{
imageChange(e);
}
}catch(Exception ee)
{
//System.out.println("Error in BUTTON:"+ee);
}
}
int playerPassNumber()
{
 int i= randomNo.nextInt(7);

         str=Integer.toString(i);
dieIcon= new ImageIcon("images/Game dies/"+str+".jpg");
die.setIcon(dieIcon);

     return i;

}

void winerdraw()
{
int i=0;
start.setEnabled(true);
restart.setEnabled(false);
JBplayer.setEnabled(false);
JBcomputer.setEnabled(true);
JBcomputer.setEnabled(false);
 
for(int k=0;k<10;k++)
for(int l=0;l<10;l++)
{
gameover=1;
         b[k][l].setIcon(winericon[k][l]);             
}

    
}


void rePrint()
{
try{

for( i=0;i<10;i++)
{
for(j=0;j<10;j++)
 {
   // b[i][j].setIcon(null);
b[i][j].setIcon(icon[i][j]);
 }
}

   }catch(Exception e)
{
//System.out.println("error in repaint"+e);
}

}

void playerimageTraval(int n)
{
int i=j=0;
int imageFlag=0;
int noFlag=0;

if(gameover==0)
{
try{
rePrint();
 for(i=0;i<10;i++)
      {
for(j=0;j<10;j++)
{
if(n==game[i][j])
   {
                noFlag=1;
break;
   }
}
  if(noFlag==1)
break;
      }

   if(noFlag==1)
{
if(imageFlag==0)
{
Thread.sleep(200);
b[i][j].setIcon(p1);
imageFlag=1;
prevIp1=i;
prevJp1=j;
       }
        else
{
path=game[prevIp1][prevJp1];
str=Integer.toString(path);
  Thread.sleep(200);
icon[prevIp1][prevJp1]=new ImageIcon("images/"+str+".jpg");
Thread.sleep(200);
       b[prevIp1][prevJp1].setIcon(icon[prevIp1][prevJp1]);
b[i][j].setIcon(p1);
prevIp1=i;
prevJp1=j;
       }

/*****************checks for staires**********************/
if(n==10)
{
n=28;
playerimageTraval(n);
p1value=n;
}
else if(n==17)
{
n=37;
playerimageTraval(n);
p1value=n;
}
else if(n==31)
{
n=70;
playerimageTraval(n);
p1value=n;
}
else if(n==45)
{
n=84;
playerimageTraval(n);
p1value=n;
}
else if(n==78)
{
n=97;
playerimageTraval(n);
p1value=n;
}


/*****************Checks for Snakes***************************/
if(n==95)
{
        n=73;
playerimageTraval(n);
p1value=n;
}
else if(n==79)
{
        n=59;
playerimageTraval(n);
p1value=n;
}
else if(n==68)
{
        n=48;
playerimageTraval(n);
p1value=n;
}
else if(n==44)
{
        n=21;
playerimageTraval(n);
p1value=n;
}
else if(n==34)
{
        n=16;
playerimageTraval(n);
p1value=n;
}

}

if(n>=100)
{   
//System.out.println("Congr u r win");
winerdraw();

}
}
catch(Exception e)
{

}
}

}

void setBothImage()
{
int i=0;
int j=0;
int noFlag=0;

if(gameover==0)
{
for(i=0;i<10;i++)
      {
for(j=0;j<10;j++)
{
if(p1value==game[i][j])
   {
                                noFlag=1;
break;
   }
}
  if(noFlag==1)
break;
      }

if(noFlag==1)
{
b[i][j].setIcon(p1);  
}

noFlag=0;

for(i=0;i<10;i++)
      {
for(j=0;j<10;j++)
{
if(p2value==game[i][j])
   {
                                noFlag=1;
break;
   }
}
  if(noFlag==1)
break;
      }

if(noFlag==1)
{
b[i][j].setIcon(p2);
}
}
}


void computerimageTraval(int n)
{
int i=j=0;
int imageFlag=0;
int noFlag=0;

try{
rePrint();
 for(i=0;i<10;i++)
      {
for(j=0;j<10;j++)
{
if(n==game[i][j])
   {
                noFlag=1;
break;
   }
}
  if(noFlag==1)
break;
      }

  if(noFlag==1)
{
if(imageFlag==0)
{
Thread.sleep(200);
b[i][j].setIcon(p2);
imageFlag=1;
prevIp1=i;
prevJp1=j;
       }
        else
{
path=game[prevIp1][prevJp1];
str=Integer.toString(path);
  Thread.sleep(200);
icon[prevIp1][prevJp1]=new ImageIcon("images/"+str+".jpg");
Thread.sleep(200);
       b[prevIp1][prevJp1].setIcon(icon[prevIp1][prevJp1]);
b[i][j].setIcon(p1);
prevIp1=i;
prevJp1=j;
       }
           

              /*****************checks for staires**********************/

if(n==10)
{
n=28;
computerimageTraval(n);
p2value=n;
}
else if(n==17)
{
n=37;
computerimageTraval(n);
p2value=n;
}
else if(n==31)
{
n=70;
computerimageTraval(n);
p2value=n;
}
else if(n==45)
{
n=84;
computerimageTraval(n);
p2value=n;
}
else if(n==78)
{
n=97;
computerimageTraval(n);
p2value=n;
}


/*****************Checks for Snakes***************************/
if(n==95)
{
        n=73;
computerimageTraval(n);
p2value=n;
}
else if(n==79)
{
        n=59;
computerimageTraval(n);
p2value=n;
}
else if(n==68)
{
        n=48;
computerimageTraval(n);
p2value=n;
}
else if(n==44)
{
        n=21;
computerimageTraval(n);
p2value=n;
}
else if(n==34)
{
        n=16;
computerimageTraval(n);
p2value=n;
}

}


if(n>=100)
{   
//System.out.println("Congr u r win");
gameover=1;
winerdraw();
}



}
catch(Exception e)
{

}


}

void imageChange(ActionEvent e)
{
int i=j=0;
int flag=0;

try{
 for( i=0;i<10;i++)
    {
for( j=0;j<10;j++)
{
if(e.getSource()==b[i][j])
{
//System.out.println("Button Found");
//System.out.println("b["+i+"]["+j+"]");
flag=1;
break;
}
//System.out.println(j);
}

if(flag==1)
break;
     }


if(imageFlag==0)

Thread.sleep(200);
b[i][j].setIcon(p1);
imageFlag=1;
prevIp1=i;
prevJp1=j;
}
    else
{
path=game[prevIp1][prevJp1];
str=Integer.toString(path);
Thread.sleep(200);
icon[prevIp1][prevJp1]=new ImageIcon("images/"+str+".jpg");
Thread.sleep(200);
       b[prevIp1][prevJp1].setIcon(icon[prevIp1][prevJp1]);
b[i][j].setIcon(p1);
prevIp1=i;
prevJp1=j; 
      }
    }
catch(Exception ee)
{
ee.printStackTrace();
}
}


/******************************Methods of MouseListener****************************/

public void mouseClicked(MouseEvent ae) 
{
 openURL("http://gauravsiwach.blogspot.com");
  
  System.out.println("Clicked");

}
public void mouseEntered(MouseEvent ae)
{
}
public void mouseExited(MouseEvent ae)
{
}
public void mousePressed(MouseEvent ae)
{
}
public void mouseReleased(MouseEvent ae)
{
}


/*******************************BrowserController*********************************/
public static void openURL(String url) 
{
                String osName = System.getProperty("os.name");
                try {
                        if (osName.startsWith("Windows"))
                                Runtime.getRuntime().exec(
                                                "rundll32 url.dll,FileProtocolHandler " + url);
                        else {
                                String[] browsers = { "firefox", "opera"};
                                String browser = null;
                                for (int count = 0; count < browsers.length && browser == null; count++)
                                        if (Runtime.getRuntime().exec(
                                                        new String[] { "which", browsers[count] })
                                                        .waitFor() == 0)
                                                browser = browsers[count];
                                Runtime.getRuntime().exec(new String[] { browser, url });
                        }
                } catch (Exception e) {
                        JOptionPane.showMessageDialog(null, "Error in opening browser"
                                        + ":\n" + e.getLocalizedMessage());
                }
      
    }



public static void main(String args[])
{
 Main m= new Main();
}
}

Game running 




you can download Source code
Snake And Ladders code