title: How can I change a JButton Color upon keyTyped event?
body: <p>My project is about creating a virtual keyboard, and the buttons on that keyboard have to change their color as the user types the respective button on their keyboard.
  ie if I type 'e', the letter 'e' on my virtual keyboard has to change its color.</p>
  
  <p>To draw my keyboard I used a 2D JButton Array, and a 2D String array, to name the buttons and assign their respective label, then I added to each button a KeyListener interface, and in that interface I instructed the program to change the color of the button. Compiling it works fine for me but the actual color change doesn't work. Can someone help?
  Here's the code</p>
  
  <pre><code>    private JButton spButton, oneButton, twoButton, threeButton, fourButton, fiveButton, sixButton, sevenButton, eightButton,
                  nineButton, zeroButton, dashButton, equalsButton, bspButton, tabButton, qButton, wButton, eButton, 
                  rButton, tButton, yButton, uButton, iButton, oButton, pButton, rBracketButton, lBracketButton, slashButton,
                  capsButton, aButton, sButton, dButton, fButton, gButton, hButton, jButton, kButton, lButton, scButton, 
                  sqButton, enterButton, lShiftButton, zButton, xButton, cButton, vButton, bButton, nButton, mButton, 
                  commaButton, periodButton, bSlashButton, rShiftButton, upButton, spaceButton, leftButton, downButton, 
                  rightButton;
  private JButton [][] buttonArray = {{spButton, oneButton, twoButton, threeButton, fourButton, fiveButton, 
      sixButton,sevenButton, eightButton, nineButton, zeroButton, dashButton, equalsButton, bspButton},
                                      {tabButton, qButton, wButton, eButton, rButton, tButton, yButton, uButton, 
          iButton, oButton, pButton, rBracketButton, lBracketButton, slashButton},
                                      {capsButton, aButton, sButton, dButton, fButton, gButton, hButton,
              jButton, kButton, lButton, scButton,  sqButton, enterButton},
                                      {lShiftButton, zButton, xButton, cButton, vButton, bButton, nButton, mButton, 
                  commaButton, periodButton, bSlashButton, rShiftButton, upButton},
                                      {spaceButton, leftButton, downButton, rightButton}};
  private char pressed;
  
  
  public constructor(){
  addKeyListener(new KeyEventsHandler());
  }
  private class KeyEventsHandler implements KeyListener {
  
          @Override
          public void keyTyped(KeyEvent e) {
  
              pressed = e.getKeyChar();
                  for (int row = 0; row &lt; keyBoard.length; row ++){
                      for (int column = 0; column &lt; keyBoard[row].length; column ++){
                          if (pressed==buttonArray[row][column].getName().toLowerCase().charAt(0))
                          buttonArray[row][column].setForeground(Color.RED);
                          keyboardPanel.repaint();
                      }
                  }
  
  
  
  
          }
  
          @Override
          public void keyReleased(KeyEvent e) {
  
          }
  
          @Override
          public void keyPressed(KeyEvent e) {
  
          }
  
  
  }
  </code></pre>
  
  <p>thanks in advance guys</p>