Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Accessing from another file

  Asked By: Jeff    Date: Dec 07    Category: Java    Views: 531
  

I'm trying to access an instance (a JTextArea) in a public class from
another file. How do I do that (this might be a little bit silly, but I haven't
done this before?) Is there a good way of doing it?

Share: 

 

2 Answers Found

 
Answer #1    Answered By: Troy Kelley     Answered On: Dec 07

If the other class  was named OtherClass

and the JTextArea was named textArea

OtherClass anotherClass = new OtherClass();
JTextArea myTextArea =anotherClass.textArea;

or

JTextArea myTextArea = (new OtherClass()).textArea;

 
Answer #2    Answered By: Gorkem Yilmaz     Answered On: Dec 07

but it will only copy the JTextArea as it once was
initialized. It won't get the content when I write something. Is there a way to
keep my new JTextArea updated from the other one?

 
Didn't find what you were looking for? Find more on Accessing from another file Or get search suggestion and latest updates.




Tagged: