Search code examples
javaswingoopjtextfield

Getting values of JTextFields from one class to another class within same package?


I want to use the values of JTextFields from one class in another class within the same package.

How can I do it?


Solution

  • Please rephrase your question !! I hope u want to access one class's textfield's value in other class's textfield.

    class Class1 
    {
          JTextField field1;
          public String getFieldText()
          {
                return field1.getText();
          }
    }
    class Class2
    {
          JTextField field2;
          Class2(Class1 c1)
          {
                field2.setText(c1.getFieldText());
          }
    }