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

(JAVA) i have 2 page on my app, main page is called MainActivity, my other page

ID: 672820 • Letter: #

Question

(JAVA) i have 2 page on my app, main page is called MainActivity, my other page is called UpdateData. On the update page i coding so the person can type in their name, surname and when they click on the update button on the UpdateData page the data is stored to a textfile.txt. When the person goes back to their MainActivity page their new updated details should appear on the mainactivity page(just the information), need help ASAP please (this is all done in eclipse)

Please provide the code in JAVA, thanks

Explanation / Answer

Below is the desired program. It is simple Java swing program. Created two frame as per requirement.

On clicking of update button , details will be shown on the main activity page.


import java.awt.Button;
import java.awt.Component;
import java.awt.FlowLayout;
import java.awt.Label;
import java.awt.TextArea;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

public class SwingTest {
   private JFrame mainActivity;
   private JFrame updateData;
   private static String firstName;
   private static String surName;
   public static void start(){
       final JFrame mainActivity = new JFrame("MainActivity");
       final Label firstNameLbl = new Label("firstName");
       firstNameLbl.setText(firstName);
       final Label surNameLbl = new Label("surName");
       surNameLbl.setText(surName);
         
       //mainActivity.setLayout(new FlowLayout());
       mainActivity.add(firstNameLbl);
       mainActivity.add(surNameLbl);
       mainActivity.setSize(400,400);
       mainActivity.setVisible(false);
      
       final JFrame updateData = new JFrame("Update Data");
       TextArea firstNameTxt = new TextArea();
       firstNameTxt.setSize(10,40);
      
       firstName = firstNameTxt.getText();
       TextArea surNameTxt = new TextArea();
  
       surNameTxt.setSize(10,40);
      
       surName = surNameTxt.getText();
       Button button = new Button("Update");
       button.addActionListener(new ActionListener() {
          
           public void actionPerformed(ActionEvent arg0) {
               updateData.setVisible(false);
               firstNameLbl.setText(firstName);
               surNameLbl.setText(surName);
              
               firstNameLbl.setSize(80, 40);
               surNameLbl.setSize(80, 40);
               mainActivity.setVisible(true);
           }
       });
       updateData.add(button);
      
         
       updateData.setLayout(new FlowLayout());
       updateData.add(firstNameTxt);
       updateData.add(surNameTxt);
      
       updateData.setSize(400,400);
       updateData.setVisible(true);
   }
   /**
   * @param args
   */main method
   public static void main(String[] args) {
       start();

   }

}