• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Swing

 
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
 
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!