Lógica

0 respostas
carlitosmed
//1QUADRANTE
              if(botao[0][2].getText().equals("7")){          	 
            	 botao[0][2].setEnabled(false);
                 botao[0][2].setBackground(null);
                 
              }              
              if(botao[0][4].getText().equals("1")){
                 botao[0][4].setEnabled(false);
                botao[0][4].setBackground(null);
              }              
              if(botao[0][5].getText().equals("3")){
            	 botao[0][5].setEnabled(false);
                 botao[0][5].setBackground(null);
              }
              if(botao[0][6].getText().equals("8")){
             	 botao[0][6].setEnabled(false);
                 botao[0][6].setBackground(null);
              }  
              if(botao[0][7].getText().equals("5")){
             	 botao[0][7].setEnabled(false);
                 botao[0][7].setBackground(null);
              }
              
              //2QUADRANTE
              if(botao[1][1].getText().equals("6")){
             	 botao[1][1].setEnabled(false);
                 botao[1][1].setBackground(null);
              }
              if(botao[1][3].getText().equals("8")){
             	 botao[1][3].setEnabled(false);
                 botao[1][3].setBackground(null);
              }
              if(botao[1][5].getText().equals("7")){
             	 botao[1][5].setEnabled(false);
                 botao[1][5].setBackground(null);
              }
              if(botao[1][7].getText().equals("9")){
             	 botao[1][7].setEnabled(false);
                 botao[1][7].setBackground(null);
              }
              
              //3QUADRANTE
              if(botao[2][0].getText().equals("3")){
             	 botao[2][0].setEnabled(false);
                 botao[2][0].setBackground(null);
              }
              if(botao[2][3].getText().equals("9")){
             	 botao[2][3].setEnabled(false);
                 botao[2][3].setBackground(null);
              }
              if(botao[2][4].getText().equals("2")){
             	 botao[2][4].setEnabled(false);
                 botao[2][4].setBackground(null);
              }
              if(botao[2][7].getText().equals("7")){
              	 botao[2][7].setEnabled(false);
                 botao[2][7].setBackground(null);
              }  
              if(botao[2][8].getText().equals("6")){
              	 botao[2][8].setEnabled(false);
                 botao[2][8].setBackground(null);
              }
               
              //4QUADRANTE
              if(botao[3][0].getText().equals("1")){
                 botao[3][0].setEnabled(false);
                 botao[3][0].setBackground(null);
              }
              if(botao[3][2].getText().equals("9")){
            	 botao[3][2].setEnabled(false);
                 botao[3][2].setBackground(null);
              }
              if(botao[3][4].getText().equals("7")){
               	 botao[3][4].setEnabled(false);
                 botao[3][4].setBackground(null);
              }
              if(botao[3][6].getText().equals("3")){
                 botao[3][6].setEnabled(false);
                 botao[3][6].setBackground(null);
              }  
              if(botao[3][8].getText().equals("4")){
                 botao[3][8].setEnabled(false);
                 botao[3][8].setBackground(null);
              }
                 
              //5QUADRANTE
              if(botao[4][1].getText().equals("8")){
                 botao[4][1].setEnabled(false);
                 botao[4][1].setBackground(null);
              }
              if(botao[4][2].getText().equals("4")){
                 botao[4][2].setEnabled(false);
                 botao[4][2].setBackground(null);
              }
              if(botao[4][3].getText().equals("9")){
                 botao[4][3].setEnabled(false);
                 botao[4][3].setBackground(null);
              }
              if(botao[4][5].getText().equals("6")){
                 botao[4][5].setEnabled(false);
                 botao[4][5].setBackground(null);
              }  
              if(botao[4][6].getText().equals("7")){
                 botao[4][6].setEnabled(false);
                 botao[4][6].setBackground(null);
              }
              if(botao[4][7].getText().equals("1")){
                 botao[4][7].setEnabled(false);
                 botao[4][7].setBackground(null);
              }
                   
               //6QUADRANTE
              if(botao[5][0].getText().equals("5")){
                 botao[5][0].setEnabled(false);
                 botao[5][0].setBackground(null);
              }
              if(botao[5][2].getText().equals("7")){
                 botao[5][2].setEnabled(false);
                 botao[5][2].setBackground(null);
              }
              if(botao[5][4].getText().equals("3")){
                 botao[5][4].setEnabled(false);
                 botao[5][4].setBackground(null);
              }
              if(botao[5][6].getText().equals("2")){
                 botao[5][6].setEnabled(false);
                 botao[5][6].setBackground(null);
              }  
              if(botao[5][8].getText().equals("9")){
                 botao[5][8].setEnabled(false);
                 botao[5][8].setBackground(null);
              }
                     
              //7QUADRANTE
              
              if(botao[6][0].getText().equals("2")){
                 botao[6][0].setEnabled(false);
                 botao[6][0].setBackground(null);                             	                                        	  
              }              
              if(botao[6][1].getText().equals("9")){
                 botao[6][1].setEnabled(false);
                 botao[6][1].setBackground(null);
              }
              if(botao[6][4].getText().equals("8")){
                 botao[6][4].setEnabled(false);
                 botao[6][4].setBackground(null);
              }
              if(botao[6][5].getText().equals("5")){
                 botao[6][5].setEnabled(false);
                 botao[6][5].setBackground(null);
              }  
              if(botao[6][8].getText().equals("6")){
                 botao[6][8].setEnabled(false);
                 botao[6][8].setBackground(null);
              }
                         
              //8QUADRANTE
              if(botao[7][1].getText().equals("3")){
                 botao[7][1].setEnabled(false);
                 botao[7][1].setBackground(null);
              }
              if(botao[7][3].getText().equals("2")){
                 botao[7][3].setEnabled(false);
                 botao[7][3].setBackground(null);
              }
              if(botao[7][5].getText().equals("1")){
                 botao[7][5].setEnabled(false);
                 botao[7][5].setBackground(null);
              }
              if(botao[7][7].getText().equals("7")){
                 botao[7][7].setEnabled(false);
                 botao[7][7].setBackground(null);
              }                       
              
              //9QUADRANTE
              if(botao[8][1].getText().equals("4")){
                 botao[8][1].setEnabled(false);
                 botao[8][1].setBackground(null);
              }
              if(botao[8][2].getText().equals("5")){
                 botao[8][2].setEnabled(false);
                 botao[8][2].setBackground(null);
              }
              if(botao[8][3].getText().equals("6")){
                 botao[8][3].setEnabled(false);
                 botao[8][3].setBackground(null);
              }
              if(botao[8][4].getText().equals("9")){
                 botao[8][4].setEnabled(false);
                 botao[8][4].setBackground(null);
              }  
              if(botao[8][6].getText().equals("8")){
                 botao[8][6].setEnabled(false);
                 botao[8][6].setBackground(null);

estou comparando se o valor inserido em [i][j] posição é igual á ("x") caso for ele bloqueia e deixa o background da mesma cor, teria como fazer de um jeito diferente invés de vários ifs? tá muito gambiarra isso, mas funcionou, mas tá monstra a gambiarra ;/

e também, tem como, caso eu clicar e inserir um valor que não seja igual á ("x") o background ficar de outra cor?
porque eu fiz por exemplo

if(botao[8][6].getText().equals("8")){
                 botao[8][6].setEnabled(false);
                 botao[8][6].setBackground(null);
  }
  else{

                 botao[8][6].setBackground(Color.red);
  }

mas não deu bão, mesmo que eu não clicasse na posição [8][6] ela ficava vermelha, alguma dica?

Criado 6 de julho de 2011
Respostas 0
Participantes 1