[SOLVED] Passing string value one gui to another


Main class

Result GUI

I am trying to add one string from main class to another gui when you hit the submit button. When the second gui comes up however, it comes up null on my firstname.

class 1 main

public class SubmitButtonHandler implements ActionListener{
    public void actionPerformed(ActionEvent e) {
        first_name = firstText.getText();
        last_name = lastText.getText();
        resultGui gui1 = new resultGui();

class 2 second gui

 public JFrame resultFrame;
    public JLabel first_name_label , last_name_label;
    private String first_name;
      public String getName() {
          return first_name;
      public void setName(String name) {
          this.first_name = name;



In your class 1 you use gui1.setName(first_name);, which will invoke

public void setName(String name) {
    this.first_name = name;

in class 2. But the value is not passed to the Label. That method probably should look like

public void setName(String name) {
    this.first_name = name;

Answered By – Hiran Chaudhuri

Answer Checked By – Cary Denson (BugsFixing Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *