• Post Reply Bookmark Topic Watch Topic
  • New Topic

Swing  RSS feed

 
Rajib Sarma
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I'm a new comer to Java. I have a problem.
How do I change the text in a TextArea from many different classes. e.g. In my project, class A displays a TextArea. Now, I want to display different messages from different classes B and C, in this textarea. What I have done is, I have created a class "Common" as -
class Common
{
//This is the text area where the messages are displayed.
static JTextArea output;
static
{
outout=new JTextArea();
}
}
Now, I'm displaying this textarea in class A as-
class A
{
public static void main(...)
{
JFrame f=new JFrame();
Container c=f.getContentPane();
c.add(Common.output);
...
}
}
Now, I'm changing the text from different classes as shown -
class B
{
...
Common.output.setText(...);
}
class C
{
...
Common.output.setText(...);
}
Is my approach correct?
Please explain.
Thanks
-Rajib
 
Sriram Viswanadham
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you may not want to use static members for this. Intead you may go for a class with GetText() and setText() methods which returns and sets the text fo teh TextArea respectively. Thus, you can set the text in the textarea with appropriate text as required.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!