Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6935285
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:04:56+00:00 2026-05-27T12:04:56+00:00

I’m working on a simple tool where a user inputs their string or RNA

  • 0

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:

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 < 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 < 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")
// <editor-fold defaultstate="collapsed" desc="Generated Code">                          
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);
}// </editor-fold>                        

/**
 * @param args the command line arguments
 */
public static void main(String args[]) {

    TranslationGUI frame = new TranslationGUI();
    /* Set the Nimbus look and feel */
    //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
    /* 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);
    }
    //</editor-fold>

    /* 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                   

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T12:04:57+00:00Added an answer on May 27, 2026 at 12:04 pm

    Your problem is that you’re shadowing variables.

    You declare your JButton variables in the class, but then re-declare them in the constructor, and so the JButton object that gets the listener attached is not referred to by the JButton variable in the class. So when your actionPerformed method checks to see if the JButton pressed is the transcribe JButton, it doesn’t match, and in fact transcribe is actually null at that point (test it and see). The solution: don’t re-declare your variable in the constructor.

    In other words, in your constructor change this:

    // this creates a new transcribe variable inside of the 
    // constructor, assigns it a JButton object, but the variable
    // is only visible inside of the constructor.
    JButton transcribe = new JButton();
    

    to this:

    // this creates a new JButton object and assigns it to the 
    // class transcribe variable.
    transcribe = new JButton();
    

    Edit
    Heck, you’re adding yet another JButton to the GUI — don’t do this!

    DNAPanel.add(new JButton("Transcribe")); // ??
    

    Add the JButton that you’ve created just above this.

    DNAPanel.add(transcribe); // add the button created just above.
    

    e.g.,

      translate = new JButton("Translate"); // give button a title
      RNAPanel.add(translate);
      translate.addActionListener(this);
    

    It’s almost as if you are trying extremely hard to make sure that the JButton variable in the class won’t work. I’m kidding of course, but you’re blocking it in 2 different ways, something I’ve never seen before — and I thought that I’ve seen everything.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I've got a string that has curly quotes in it. I'd like to replace
Specifically, suppose I start with the string string =hello \'i am \' me And

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.