Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

dna Class public class dnaGUI extends JFrame implements ActionListener{ private

ID: 3649837 • Letter: D

Question

dna Class
public class dnaGUI extends JFrame implements ActionListener{
private JPanel panel;
private JTextArea textArea;

/** The Constant FRAME_HEIGHT. */
static final int FRAME_HEIGHT = 200;

/** The Constant FRAME_WIDTH. */
static final int FRAME_WIDTH = 300;

dnaGUI(){
super("DNA segments interface");
setLayout(new FlowLayout());
setDefaultCloseOperation(EXIT_ON_CLOSE);
add(r1);
add(dna);
add(r2);
add(protein);
//add(submit);
add(storenSequences);
acid.setEditable(false);
setVisible(true);
//submit.addActionListener(this);
this.setSize(FRAME_WIDTH, FRAME_HEIGHT);
}

//makes a label for DNA sequences
JLabel r1 = new JLabel("Enter DNA Sequences "); //works
JLabel r2 = new JLabel("AminoAcids result ");

String nSequences = new String();
String nAminoAcids = new String();
JTextArea storenSequences = new JTextArea(20,30);

// textArea = new JTextArea(2,20); //create text area in middle of window
// add(textArea); //throw the text area in window

//input field for dna sequence
JTextField dna = new JTextField(20);

//output field for amino acids
JTextField protein = new JTextField(20);


the strings comes from my other class named protein
private static String[] nSequences = {"ATG", "GCA", "ACG", "TGA", "ATT", "TAG", "TAA","TTA", "TTT", "TTC", "TTG", "CTT", "CTC", "ATC", "ATA", "GTT", "GTC", "GTA", "GTG", "TCT", "TCC","TCA","TCG","CCT", "CCC","CCA","CCG","ACT","ACC","ACA","ACG","GCT","GCC","GCG","TAT","TAC","CAT","CAC","CAA", "CAG","AAT","AAC","AAA","AAG","GAT","GAC","GAA","GAG","TGT","TGC","TGG","CGT","CGC","CGA","CGG","AGT","AGC","AGA","AGG","GGT","GGC","GGA","GGG"}; //assign string to variable
//second word that shows after user input three letters
private static String [] nAminoAcids = {"Met", "Ala", "Thr"};

basically a user will enter "ATGGCATGA" click a button then it will output "MetAlaThr" (from other string)?
how to create a button on my GUI?
how to add both static string on my textfield?
how to use loop to search each triple letters?

Explanation / Answer

import java.awt.*; import javax.swing.*; import java.awt.event.*; public class dnaGUI extends JFrame implements ActionListener{ private JButton button1; private JPanel panel; private JTextField textField; private JTextArea textArea; private JLabel Sequences, AminoAcids; public static void main() { dnaGUI myFrame = new dnaGUI(); myFrame.setSize(310,200); myFrame.dnaGUI(); myFrame.setTitle("DNA Graphic User Inteface"); myFrame.setVisible(true); } private void dnaGUI() { setDefaultCloseOperation(EXIT_ON_CLOSE); Container window = getContentPane(); window.setLayout(new FlowLayout()); //makes a label for DNA sequences {Sequences = new JLabel("DNA Sequences"); add(Sequences); add(Sequences);} //label = new JLabel("Protein "); //add(label); textArea = new JTextArea(2,20); //create text area in middle of window add(textArea); //throw the text area in window // use one class to handle all of the buttons button1 = new JButton("CLICK HERE"); textField = new JTextField(20); //adding actions to buttons textField.addActionListener(this); button1.addActionListener(this); // add buttons to the window window.add(button1); window.add(textField); //makes a label for aminoacids results //putting this code lower in those code smove the label { AminoAcids = new JLabel("Amino Acids result"); add(AminoAcids); add(AminoAcids);} // add the panel to the window panel = new JPanel(); panel.setPreferredSize(new Dimension(200,200)); window.add(panel); } private final static String newline = " "; public void actionPerformed(ActionEvent e){ //initializing the action String text = textField.getText(); textArea.append(text + newline); textField.selectAll(); } }