How can i get the inputted text in a textfield from another frame to the 2nd frame?
Here is the syntax... on the fi开发者_如何学编程rst frame
JTextField tf1 = new JTextField();
from the bottom there has the actionListener
this.setVisible(false);
new Display().setVisible(true);
Now on the 2nd Frame i want to create a text field that automatically display the one I typed in the textfield on first frame. (but when I try to call the tf1 variable, it cannot be resolved.)
Maintain an object reference to the textfield you want to get the text from and also the one you want to copy the text to, and then the methods getText()
and setText()
will do what you require.
If you need more help, I suggest you add some more specific details to your question, perhaps along with some example code.
How about this suggestion:
- subclass frame, call the class something like TextFrame
- add a constructor to TextFrame that adds a new field that is the textField you are going to edit, called
theTextField
- add a method to TextFrame named
public String getText()
that gets the text from theTextField when it is called - add a method to TextFrame named
public void setText(String text)
that sets the text in theTextField when it is called - from your main class, create a new TextFrame instance named inputTextFrame and one named outputTextFrame
- then call getText on the inputTextFrame and pass this string to the
outputTextFrame.setText()
When you want to call the last point is up to the business logic of your application
精彩评论