title: DNA to RNA Conversion Java Swing: Why aren't my JButtons working?
body: <p>I'm working on a simple tool where a user inputs their string or RNA or DNA and clicks a button which then transcribes it. When I click my transcribe or reverse transcribe JButton nothing happens! Please help! Any direction, hints or help would be great! Thank you! Here is my code:</p>
  
  <pre><code>import java.awt.BorderLayout;
  import java.awt.Choice;
  import java.awt.Color;
  import java.awt.Dimension;
  import java.awt.FlowLayout;
  import java.awt.GridLayout;
  import java.awt.TextArea;
  import java.awt.event.ActionEvent;
  import java.awt.event.ActionListener;
  import javax.swing.JButton;
  import javax.swing.JFrame;
  import javax.swing.JLabel;
  import javax.swing.JPanel;
  import java.awt.event.*;
  
  public class TranslationGUI extends javax.swing.JFrame implements ActionListener
  {
      public static final int WIDTH = 1500;
      public static final int HEIGHT = 500;
  
      TextArea DNATextArea, RNATextArea, proteinTextArea;
      JButton transcribe, translate, reverseTranscribe;
      String DNA;
      String RNA;
  
  /** Creates new form TranslationGUI */
  public TranslationGUI() 
  {
      super("Transcription and Translation Tool");
      setSize(WIDTH, HEIGHT);
      setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      setLayout(new FlowLayout());     
  
      JPanel DNAPanel = new JPanel();
      DNAPanel.setPreferredSize(new Dimension(440,400));
      DNAPanel.add(new JLabel("DNA Sequence"));
      TextArea DNATextArea = new TextArea();
      DNAPanel.add(DNATextArea);
      DNATextArea.setEditable(true);
      DNAPanel.add(new JLabel("DNA (deoxyribonucleic acid)"));
      JButton transcribe = new JButton();
      DNAPanel.add(new JButton("Transcribe"));
      transcribe.addActionListener(this);
      add(DNAPanel, BorderLayout.WEST);
      DNAPanel.setBackground(Color.WHITE);
  
      JPanel RNAPanel = new JPanel();
      RNAPanel.setPreferredSize(new Dimension(440,400));
      RNAPanel.add(new JLabel("RNA Sequence"));
      TextArea RNATextArea = new TextArea();
      RNATextArea.setEditable(true);
      RNAPanel.add(RNATextArea);
      RNAPanel.add(new JLabel("RNA (ribonucleic acid)"));
      JButton translate = new JButton();
      RNAPanel.add(new JButton("Translate"));
      translate.addActionListener(this);
      JButton reverseTranscribe = new JButton();
      RNAPanel.add(new JButton("Reverse Transcribe"));
      reverseTranscribe.addActionListener(this);
      add(RNAPanel, BorderLayout.CENTER);
      RNAPanel.setBackground(Color.LIGHT_GRAY);
  
      JPanel proteinPanel = new JPanel();
      proteinPanel.setPreferredSize(new Dimension(440,400));
      proteinPanel.add(new JLabel("Protein Sequence"));
      TextArea proteinTextArea = new TextArea();
      proteinPanel.add(proteinTextArea);
      proteinPanel.add(new JLabel("Protein"));
      add(proteinPanel, BorderLayout.EAST);
      proteinPanel.setBackground(Color.WHITE);
  
      pack();
  }
  
  public void actionPerformed(ActionEvent event) 
  {
      if(event.getSource()== transcribe)
      {
          DNATranscription();
      }
      else if(event.getSource()== reverseTranscribe)
      {
          RNATranscription();
      }
  else if(event.getSource()== translate)
      {   
          Translate();
  }
  }
  
  public void DNATranscription()
  {   
      String DNA = DNATextArea.getText();
      char[] reverse = new char[DNA.length()];
      for (int i = 0; i &lt; reverse.length; i++) 
      {
          switch(DNA.charAt(i)) 
          {
              case 'A': reverse[i] = 'T';break;
              case 'T': reverse[i] = 'A';break;
              case 'C': reverse[i] = 'G';break;
              case 'G': reverse[i] = 'C';break;
              default: 
                  System.out.println("Not a DNA code");
          }
      }
      DNA = new String(reverse);
      RNATextArea.append(DNA);
  }
  
  public void RNATranscription()
  {   
      String RNA = RNATextArea.getText();
      char[] reverse = new char[RNA.length()];
      for (int i = 0; i &lt; reverse.length; i++) 
      {
          switch(RNA.charAt(i)) 
          {
              case 'T': reverse[i] = 'A';break;
              case 'A': reverse[i] = 'T';break;
              case 'G': reverse[i] = 'C';break;
              case 'C': reverse[i] = 'G';break;
              default: 
                  System.out.println("Not a RNA code");
          }
      }
      RNA = new String(reverse);
      DNATextArea.append(RNA);
  }
  
  public void Translate()
  {
      //do something
  }
  
  private static final String[][] CODON_AMINO = //table for the codon
                                             //that corresponds to a protein
      {
       {"att", "i"}, {"atc", "i"}, {"ata", "i"}, {"ctt", "l"},
       {"ctc", "l"}, {"cta", "l"}, {"ctg", "l"}, {"tta", "l"},
       {"ttg", "l"}, {"gtt", "v"}, {"gtc", "v"}, {"gta", "v"},
       {"gtg", "v"}, {"ttt", "f"}, {"ttc", "f"}, {"atg", "m"},
       {"tgt", "c"}, {"tgc", "c"}, {"gct", "a"}, {"gcc", "a"},
       {"gca", "a"}, {"gcg", "a"}, {"ggt", "g"}, {"ggc", "g"},
       {"gga", "g"}, {"ggg", "g"}, {"cct", "p"}, {"ccc", "p"},
       {"cca", "p"}, {"ccg", "p"}, {"act", "t"}, {"acc", "t"},
       {"aca", "t"}, {"acg", "t"}, {"tct", "s"}, {"tcc", "s"},
       {"tca", "s"}, {"tcg", "s"}, {"agt", "s"}, {"agc", "s"},
       {"tat", "y"}, {"tac", "y"}, {"tgg", "w"}, {"caa", "q"},
       {"cag", "q"}, {"aat", "n"}, {"aac", "n"}, {"cat", "h"},
       {"cac", "h"}, {"gaa", "e"}, {"gag", "e"}, {"gat", "d"},
       {"gac", "d"}, {"aaa", "k"}, {"aag", "k"}, {"cgt", "r"},
       {"cgc", "r"}, {"cga", "r"}, {"cgg", "r"}, {"aga", "r"},
       {"agg", "r"}
      };
  
  /** 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() {
  
      setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  
      javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
      getContentPane().setLayout(layout);
      layout.setHorizontalGroup(
          layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
          .addGap(0, 400, Short.MAX_VALUE)
      );
      layout.setVerticalGroup(
          layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
          .addGap(0, 300, Short.MAX_VALUE)
      );
  
      java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
      setBounds((screenSize.width-416)/2, (screenSize.height-338)/2, 416, 338);
  }// &lt;/editor-fold&gt;                        
  
  /**
   * @param args the command line arguments
   */
  public static void main(String args[]) {
  
      TranslationGUI frame = new TranslationGUI();
      /* 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(TranslationGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
      } catch (InstantiationException ex) {
          java.util.logging.Logger.getLogger(TranslationGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
      } catch (IllegalAccessException ex) {
          java.util.logging.Logger.getLogger(TranslationGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
      } catch (javax.swing.UnsupportedLookAndFeelException ex) {
          java.util.logging.Logger.getLogger(TranslationGUI.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 TranslationGUI().setVisible(true);
          }
      });
  }
  // Variables declaration - do not modify                     
  // End of variables declaration                   
  
  }
  </code></pre>