title: Check for adjacent cells in a 5x6 matrix
body: <p>I have a 5x6 matrix which I have created using individual buttons in Java Swing.</p>
  
  <p>I have named them similar to a chess board, as A1 to F5 from top left to bottom right.</p>
  
  <p>Now, I want to allow the user to click only a given number of adjacent buttons, either horizontally or vertically.</p>
  
  <p>Say, the value is 4. So, the user must be able to select only 4 buttons anywhere in the matrix which are next to each other vertically or horizontally.</p>
  
  <p>For eg. D2, C2, B2, A2 if chosen vertically.
  Or, maybe D1, D2, D3, D4 if chosen horizontally.</p>
  
  <p>What would be the algorithmic way of achieving this functionality for any set of buttons in the matrix?</p>