Passing.getText() String to another class
        Posted  
        
            by 
                DanMc
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by DanMc
        
        
        
        Published on 2012-04-08T23:25:50Z
        Indexed on 
            2012/04/08
            23:28 UTC
        
        
        Read the original article
        Hit count: 235
        
I'm currently working on a first year university project and I have a problem, although I doubt it's a very complicated one, but I've been searching and I just can't find a suitable answer to it.
The problem concerns two classes. A gui class (class1) and another class (class2).
I have a JTextField in class1 and am trying to pass through the .getText() value to class2 and store it in a String type variable.
The current code I'm trying to achieve this with is the following:
 (Class1)
private JTextField textField = new JTextField("Something");
    ...
public String getTextFieldString() {
      return textField.getText();
  }
 (Class2)
    private c1 Class1 = new Class1();
    private String s = new String();
    ...
    s = c1.getTextFieldString();
I'm pretty new to coding, I've read that maybe I need to pass through an argument somewhere and I assume that's because textField is not static in itself, it changes when somebody enters a new value. (sorry for stating the obvious there.)
Anyway, help is appreciated. Thanks a lot!
© Stack Overflow or respective owner