Hi i need an event handler method to let an user use the 4 arrow keys (up,down,left,right) from a keyboard input ... and also the letters "Y" for yes and "N" for no on the keyboard.

import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;

//group Albers, Rodriguez, Gonzalez, Leys, Larson, and Aponte
public class Main {

    public static void main(String[] args) {
      
        int array [][] = {{2,2,2,0},{1,1,2,0},{0,0,3,0}};//FOR TESTING
        boolean end_not_reached = true;
        boolean Valid_move = false;
        char Move = 'z';
        int array2[][];
         CreateArray ca = new CreateArray();
        try {
            ca.Fillboard();
        } catch (IOException ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        }
         array2 = ca.getGameboarda();
         System.out.println("array2 is :" + array2[2][2]);

       //NEED TO CALL CREATEARRAY AS METHOD OR FROM LINKED LIST
        //THAT ARRAY WILL REPLACE THE ONE ABOVE

      LinkedList link = new LinkedList(); // Recursive LinkedList
      CreatePath cp = new CreatePath(array2);// Recursive LinkedList
      link = cp.getPath();// Recursive LinkedList
      link.printNodes();// Recursive LinkedList

      while (end_not_reached)
      {
         //code to show the maze
         char Switch = GetData.getChar("It's your move user:  Would you like to switch positions?  (Y)es or (N)o");
                if (Switch == 'Y')
                {
                    //call switch method
                }
          // show maze after switch


          while (!Valid_move)
          {
             Move = GetData.getChar("Where would you like to move? (U)p (D)own (L)eft or (R)ight");  
             //call to valid move is in range and not a wall
             Valid_move = true; //will be removed after method above is working
          }

         switch (Move)
        {
            case 'u': case 'U':
                //call move method with u
                break;
            case 'd': case 'D':
                //call move method with D
                break;
            case 'l': case 'L':
               //call move method with L
                break;

            default: //call move method with R;
                break;
        }
              // call method check winner  end_not_reached = false;

              // call show maze

              // call random switch sets switch to char
               if (Switch == 'Y')
                {
                    //call switch method
                }
          // show maze after switch

              // call random direction sets Move to char u,d,l, or r

              switch (Move)
        {
            case 'u': case 'U':
                //call move method with u
                break;
            case 'd': case 'D':
                //call move method with D
                break;
            case 'l': case 'L':
               //call move method with L
                break;

            default: //call move method with R;
                break;
        }
              //check for winner
              //display maze

         end_not_reached = false;

      }//end while



     

      //TRYING TO GET THE RANDOM METHOD TO WORK AS A CLASS INSTEAD OF INSIDE MAIN
   
     
      //NEED TO CALL THE GUI METHOD TO SHOW THE STARTING MAZE
      // SHOW START AND END POSITION

      

    }
}

Hi i need an event handler method to let an user use the 4 arrow keys (up,down,left,right) from a keyboard input ... and also the letters "Y" for yes and "N" for no on the keyboard.

ow key ... you need an event handler ... and your question is?
P.S. please, do not answer with: "could you write it for me?"

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.