title: Is there a better way of making the code I made? char array, keylisteners
body: <p>I want to make a dialog box popup when I press a letter on the keyboard. This way I made it, I have a really long char array. Is there a better way to make this code?</p>
  
  <pre><code>    @Override
      public void keyPressed(KeyEvent e) {
          char[] alphabet = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'}; 
          char c = e.getKeyChar();
          char a = alphabet[0];
          for(int i = 0; i &lt; alphabet.length;i++) {
              a = alphabet[i];
              if(c == a)
                  JOptionPane.showMessageDialog(panel, "Error: "+c, " cannot be used", JOptionPane.WARNING_MESSAGE);
          }
      }
  </code></pre>