0

how can we form a 2d array in jsp so that we can select its element just by clicking on the particular element..

2
Contributors
2
Replies
12
Views
3 Years
Discussion Span
Last Post by irhs
0

thanks for reply..heres my java code now i want to do it in jsp and want my array to be interactive i,e i want a array of buttons so that i can select its elements just by clicking on it and get my count,can u provide me with something that will help me to print an array of buttons in java,as i m new to jsp don't know how to do it and didn't get anything from google also..

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package matrix;

import java.util.Scanner;



public class Matrix {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
         char Matrix [] []={

         {'R','B','R','B','R','B','R','B','R'},
         {'R','B','R','R','R','R','R','B','R'},
         {'R','B','R','R','R','R','R','B','R'},
         {'R','B','R','R','R','R','R','B','R'},
         {'R','B','R','R','R','R','R','B','R'},
         {'R','B','R','B','R','B','R','B','R'},
         {'R','B','R','B','R','B','R','B','R'},
         {'R','B','R','B','R','B','R','B','R'},
         {'R','B','R','B','R','B','R','B','R'}

      };

      int i,j;
      for(i=0;i<9;i++)
      {
         for(j=0;j<9;j++)
            System.out.print(Matrix [i] [j] + " ");
         System.out.println();
      }
      System.out.println("Enter the element to find its weight:"+" ");
       Scanner in = new Scanner(System.in);


      int r = in.nextInt();
      int c = in.nextInt();
       System.out.println("Entered element:"+" "+Matrix [r] [c] );


  int count=0;


           if( r-1>=0 && r+1<9 && c-1>=0 && c+1<9 && Matrix[r-1] [c]==Matrix[r] [c]){
               count++;

           }    
         if(r-1>=0 && r+1<9 && c-1>=0 && c+1<9 && Matrix[r-1] [c-1]==Matrix[r] [c]){
           count++;

       } if(r-1>=0 && r+1<9 && c-1>=0 && c+1<9 && Matrix[r-1] [c+1]==Matrix[r] [c]){
           count++;
       }  if(r-1>=0 && r+1<9 && c-1>=0 && c+1<9 && Matrix[r] [c-1]==Matrix[r] [c]){
           count++;
       }  if(r-1>=0 && r+1<9 && c-1>=0 && c+1<9 && Matrix[r] [c+1]==Matrix[r] [c]){
           count++;
       } if(r-1>=0 && r+1<9 && c-1>=0 && c+1<9 && Matrix[r+1] [c-1]==Matrix[r] [c]){
           count++;
       }  if(r-1>=0 && r+1<9 && c-1>=0 && c+1<9  && Matrix[r+1] [c]==Matrix[r] [c]){
           count++;
       } if(r-1>=0&& r+1<9 && c+1<9 && c>=0 && Matrix[r+1] [c+1]==Matrix[r] [c]){
           count++;  }  


       if(r==0&&c==0){
         if(Matrix[r] [c+1]==Matrix[r] [c]){
           count++;}

           if( Matrix[r+1] [c]==Matrix[r] [c]){
           count++;}
           if( Matrix[r+1] [c+1]==Matrix[r] [c]){
           count++;  } 

       }

       if(r==0&&c==8){
         if(Matrix[r] [c-1]==Matrix[r] [c]){
           count++;}

           if( Matrix[r+1] [c]==Matrix[r] [c]){
           count++;}
           if( Matrix[r+1] [c-1]==Matrix[r] [c]){
           count++;  } 

       }

       if(r==0&&c==0){
         if(Matrix[r] [c+1]==Matrix[r] [c]){
           count++;}

           if( Matrix[r+1] [c]==Matrix[r] [c]){
           count++;}
           if( Matrix[r+1] [c+1]==Matrix[r] [c]){
           count++;  } 

       }

       if(r==8&&c==0){
         if(Matrix[r] [c+1]==Matrix[r] [c]){
           count++;}

           if( Matrix[r-1] [c]==Matrix[r] [c]){
           count++;}
           if( Matrix[r-1] [c+1]==Matrix[r] [c]){
           count++;  } 

       }    

       if(r==8&&c==8){
         if(Matrix[r] [c-1]==Matrix[r] [c]){
           count++;}

           if( Matrix[r-1] [c]==Matrix[r] [c]){
           count++;}
           if( Matrix[r-1] [c-1]==Matrix[r] [c]){
           count++;  } 

       }
       /** top**/
       if(r==0&& c>0&&c<8 ){

           if( Matrix[r+1] [c-1]==Matrix[r] [c]){
           count++;
       }  if( Matrix[r+1] [c]==Matrix[r] [c]){
           count++;
       } if( Matrix[r+1] [c+1]==Matrix[r] [c]){
           count++;  } 

       if (Matrix[r] [c-1]==Matrix[r] [c]){
           count++;
       }  if( Matrix[r] [c+1]==Matrix[r] [c]){
           count++;
       }

       }
      /** bottom*/ 
       if(r==8&& c>0&&c<8 ){

           if( Matrix[r-1] [c-1]==Matrix[r] [c]){
           count++;
       }  if( Matrix[r-1] [c]==Matrix[r] [c]){
           count++;
       } if( Matrix[r-1] [c+1]==Matrix[r] [c]){
           count++;  } 

       if (Matrix[r] [c-1]==Matrix[r] [c]){
           count++;
       }  if( Matrix[r] [c+1]==Matrix[r] [c]){
           count++;
       }

       }


       /** left side*/
       if(c==0&& r>0&&r<8 ){

           if( Matrix[r-1] [c]==Matrix[r] [c]){
           count++;
       }  if( Matrix[r-1] [c+1]==Matrix[r] [c]){
           count++;
       } if( Matrix[r+1] [c]==Matrix[r] [c]){
           count++;  } 

       if (Matrix[r+1] [c+1]==Matrix[r] [c]){
           count++;
       }  if( Matrix[r] [c+1]==Matrix[r] [c]){
           count++;
       }

       }
       /* right side */
       if(c==8&& r>0&&r<8 ){

           if( Matrix[r-1] [c-1]==Matrix[r] [c]){
           count++;
       }  if( Matrix[r-1] [c]==Matrix[r] [c]){
           count++;
       } if( Matrix[r+1] [c-1]==Matrix[r] [c]){
           count++;  } 

       if (Matrix[r+1] [c+1]==Matrix[r] [c]){
           count++;
       }  if( Matrix[r] [c-1]==Matrix[r] [c]){
           count++;
       }

       }

      //}


       System.out.println();
      System.out.println("count=" +" "+ count); 

    }
}
This topic 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.