开发者

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:

  1. subclass frame, call the class something like TextFrame
  2. add a constructor to TextFrame that adds a new field that is the textField you are going to edit, called theTextField
  3. add a method to TextFrame named public String getText() that gets the text from theTextField when it is called
  4. add a method to TextFrame named public void setText(String text) that sets the text in theTextField when it is called
  5. from your main class, create a new TextFrame instance named inputTextFrame and one named outputTextFrame
  6. 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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜