title: Using KeyListener for a Calculator in NetBeans
body: <p>I have written a calculator in NetBeans and it functions perfectly. However, I have to actually click the buttons to insert numbers and am trying to remedy that with a KeyListener. I have all my numbers and function buttons set inside a JPanel named buttons. I have my display label in a JPanel named display.</p>
  
  <p>I set my class to implement KeyListener and it inserted the KeyPressed, -Typed, and -Released methods; however I stuck from there. I'm not sure how to make my buttons actually listen for the KeyPressed event, and when it hears the event - activate the button. Also, my buttons are named by their number (e.g. the Zero Button is named zero, One button is one, etc.).</p>
  
  <p>I've read that you actually have to implement a KeyListener somewhere by using: something.addKeyListener(something);
  but I cannot seem to figure this out.</p>
  
  <p>Can I get some help here? I'm new to Java and this is my first solo project. And let me know if I didn't provide enough information.</p>
  
  <p>EDIT: Most of my code is NetBeans Generated and I cannot edit the initialization of the components which seems to be my problem I think?</p>
  
  <p>My class declaration:</p>
  
  <pre><code>public class Calculator extends javax.swing.JFrame implements KeyListener {
   //Creates new form Calculator
  public Calculator() {
      initComponents();
  }
  </code></pre>
  
  <p>One of my buttonPressed actions (all identical with changes for actual number):</p>
  
  <pre><code>private void zeroActionPerformed(java.awt.event.ActionEvent evt) {                                     
      if (display.getText().length() &gt;= 16)
      {
          JOptionPane.showMessageDialog(null, "Cannot Handle &gt; 16 digits");
          return;
      }
      else if (display.getText().equals("0"))
      {
          return;
      }
      display.setText(display.getText().concat("0"));
  </code></pre>
  
  <p>Main method supplied by NetBeans:</p>
  
  <pre><code>public static void main(String args[]) {
      /* Create and display the form */
      java.awt.EventQueue.invokeLater(new Runnable() {
          @Override
          public void run() {
              new Calculator().setVisible(true);
          }
      });
  }
  </code></pre>
  
  <p>The initComponents() netbeans generated is absolutely massive (about 500 lines of code) and I cannot edit any of it. Let me know if I can supply any more helpful information. </p>