2

Consider the code :

private String mode;        // current played mode

private void func(int row , int column)
{
    // rotation mode 
    if ((row == 0 && column == 0) || (row == 2 && column == 0) || (row == 0 && column == 2) || (row == 2 && column == 2)) 
    {
        mode = ROTATE_MODE;
    }

    // scaling more 
    else if ((row == 0 && column == 1) || (row == 1 && column == 0) || (row == 2 && column == 1) || (row == 1 && column == 2)) 
    {
        mode = SCALE_MODE;
    }

    // translate mode
    else if ((row == 1 && column == 1)) 
    {
        mode = TRANSLATE_MODE;
    }
}

How can I use a Switch-case for row and column?

Jack cole
  • 447
  • 2
  • 8
  • 24
  • Have you already checked http://stackoverflow.com/questions/15991167/switch-case-for-two-int-variables? It may be useful to you. – Lucia Pasarin Apr 27 '13 at 14:24

2 Answers2

6

Depending on the range of the values you can use a formula

switch(row * 10 + column) {
   case 0, 20, 2, 22:

       break;
   case 1, 10, 21, 12:

       break;
   case 11:

       break;
 }
Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130
3

You could combine them into one variable. For example, if the maximum number of columns is 100 (0-99):

int position = row * 100 + column;
switch (position) {
  case 0: // row 0, col 0
  case 200: // row 2, col 0
  case 2: // row 0, col 2
  case 202: // row 2, col 2
    this.m_mode = ROTATE_MODE;
    break;
  ...
}
Alvin Thompson
  • 5,388
  • 3
  • 26
  • 39