title: How to SUBMIT a button with Enter Key in NetBeans GUI
body: <p>I have seen other posts here but I did not understand how to do that in my code.Also, I want to know if I have 3 buttons, can all of them be hit with Enter?</p>
  
  <p>My code:</p>
  
  <pre><code>public class Gadhagasker extends javax.swing.JFrame {
  
  /**
   * Creates new form Gadhagasker
   */
  public Gadhagasker() {
      initComponents();
  }
  
  /**
   * This method is called from within the constructor to initialize the form.
   * WARNING: Do NOT modify this code. The content of this method is always
   * regenerated by the Form Editor.
   */
  @SuppressWarnings("unchecked")
  // &lt;editor-fold defaultstate="collapsed" desc="Generated Code"&gt;                          
  private void initComponents() {
  
      jLabel1 = new javax.swing.JLabel();
      jLabel2 = new javax.swing.JLabel();
      jLabel3 = new javax.swing.JLabel();
      jTextField1 = new javax.swing.JTextField();
      jTextField2 = new javax.swing.JTextField();
      jButton1 = new javax.swing.JButton();
      jButton2 = new javax.swing.JButton();
      jButton3 = new javax.swing.JButton();
  
      setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
      setBackground(new java.awt.Color(51, 51, 255));
  
      jLabel1.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
      jLabel1.setText("Gadhagasker");
  
      jLabel2.setBackground(new java.awt.Color(204, 255, 255));
      jLabel2.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
      jLabel2.setText("User");
  
      jLabel3.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
      jLabel3.setText("Gadhagasker");
  
      jTextField2.setEditable(false);
      jTextField2.addActionListener(new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
              jTextField2ActionPerformed(evt);
          }
      });
  
      jButton1.setText("Enter");
      jButton1.addActionListener(new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
              jButton1ActionPerformed(evt);
          }
      });
  
      jButton2.setText("Clear");
      jButton2.addActionListener(new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
              jButton2ActionPerformed(evt);
          }
      });
  
      jButton3.setText("Exit");
      jButton3.addActionListener(new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
              jButton3ActionPerformed(evt);
          }
      });
  
      javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
      getContentPane().setLayout(layout);
      layout.setHorizontalGroup(
          layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
          .addGroup(layout.createSequentialGroup()
              .addGap(30, 30, 30)
              .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                  .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 61, javax.swing.GroupLayout.PREFERRED_SIZE)
                  .addComponent(jLabel3))
              .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
              .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                  .addComponent(jTextField1, javax.swing.GroupLayout.DEFAULT_SIZE, 466, Short.MAX_VALUE)
                  .addComponent(jTextField2))
              .addContainerGap())
          .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
              .addGap(0, 242, Short.MAX_VALUE)
              .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                  .addGroup(layout.createSequentialGroup()
                      .addComponent(jLabel1)
                      .addGap(370, 370, 370))
                  .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                      .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                      .addGap(127, 127, 127)
                      .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE)
                      .addGap(89, 89, 89))))
          .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
              .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
              .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE)
              .addGap(198, 198, 198))
      );
      layout.setVerticalGroup(
          layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
          .addGroup(layout.createSequentialGroup()
              .addContainerGap()
              .addComponent(jLabel1)
              .addGap(39, 39, 39)
              .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                  .addComponent(jLabel2)
                  .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
              .addGap(18, 18, 18)
              .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                  .addComponent(jLabel3)
                  .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
              .addGap(56, 56, 56)
              .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                  .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
                  .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE))
              .addGap(30, 30, 30)
              .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
              .addContainerGap(140, Short.MAX_VALUE))
      );
  
      pack();
  }// &lt;/editor-fold&gt;                        
  
  private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
      // TODO add your handling code here:
      String Give = jTextField1.getText();
      String[] Answer = {"Hi", "My name is Gadhagasker.", "I am fine.", "My breakfast was awesome.", "The computer where I am in now.", "Yes, but I am not ready to be responsive yet.", "Oh, upto 16 till now.", "You are my user.", "Sorry, I cannot do much.", "Ask my name again :)", "I have no sex.", "That is how I was made.", "My developer is working on it.", "I will give no more new answers.", "You are welcome.", "Please be calm.", "lol, haha", "Good Bye"};
      String[] Question = {"hi", "what is your name?", "how are you?", "how was your breakfast?", "whom do you love most?", "will you ask my name?", "how many questions can i ask you?", "can you tell me who i am?", "i am bored with you.", "i do not know what more to ask.", "are you male or female?", "You are an idiot.", "You need improvement.", "if i ask 16 questions, what would happen?", "thank you!", "go away.", "i am laughing at you.", "good bye!"};
      for (int j = 0; j &lt; Question.length - 14; j++) {
          int a = 0;
          String question = Give.toLowerCase();
          for (int i = 0; i &lt; Question.length; i++) {
  
                if (question.equals(Question[i])) {
                  jTextField2.setText(Answer[i]);
                  a = 1;
                  break;
              }
  
          }
          if (a == 0 &amp;&amp; !question.equals("")) {
              jTextField2.setText("Sorry, I cannot answer that, I am still learning.");
          }
          if (j == 15) {
              jTextField2.setText("I am done.");
          }
      }
  }                                        
  
  private void jTextField2ActionPerformed(java.awt.event.ActionEvent evt) {                                            
      // TODO add your handling code here:
  }                                           
  
  private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                         
      // TODO add your handling code here:
      jTextField1.setText("");
      jTextField2.setText("");
  }                                        
  
  private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {                                         
      // TODO add your handling code here:
      System.exit(0);
  }                                        
  
  /**
   * @param args the command line arguments
   */
  public static void main(String args[]) {
      /* Set the Nimbus look and feel */
      //&lt;editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) "&gt;
      /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
       * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
       */
      try {
          for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
              if ("Nimbus".equals(info.getName())) {
                  javax.swing.UIManager.setLookAndFeel(info.getClassName());
                  break;
              }
          }
      } catch (ClassNotFoundException ex) {
          java.util.logging.Logger.getLogger(Gadhagasker.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
      } catch (InstantiationException ex) {
          java.util.logging.Logger.getLogger(Gadhagasker.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
      } catch (IllegalAccessException ex) {
          java.util.logging.Logger.getLogger(Gadhagasker.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
      } catch (javax.swing.UnsupportedLookAndFeelException ex) {
          java.util.logging.Logger.getLogger(Gadhagasker.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
      }
      //&lt;/editor-fold&gt;
  
      /* Create and display the form */
      java.awt.EventQueue.invokeLater(new Runnable() {
          public void run() {
              new Gadhagasker().setVisible(true);
          }
      });
  }
  
  // Variables declaration - do not modify                     
  private javax.swing.JButton jButton1;
  private javax.swing.JButton jButton2;
  private javax.swing.JButton jButton3;
  private javax.swing.JLabel jLabel1;
  private javax.swing.JLabel jLabel2;
  private javax.swing.JLabel jLabel3;
  private javax.swing.JTextField jTextField1;
  private javax.swing.JTextField jTextField2;
  // End of variables declaration                   
  }
  </code></pre>
  
  <p>I need someone to write the button acion in my code so that if enter key is hit, it is submitted.</p>