This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Journey To Enterprise Agility and have Daryl Kulak & Hong Li on-line!
See this thread for details.
Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • 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:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

appending message in TextArea  RSS feed

 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Class A contains a text area:



I have an message that needs to be displayed in that text area, but it is generated by code in Class B. I got an error message that I cannot use a non-static variable in a static context, so I created an instance of Class A and its text area within Class B :



A button triggers the cancel() function in Class B. I know that works because the system will print out the message, but the text area will not. What am I missing?

thank you!
 
Bartender
Posts: 825
5
Java Python Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you sure you can compile this? What's the event in your method, I can't see you declared it and what is the purpose of that cancel() method on event object?

I suppose that A reference in your B class is not the frame you are actually displaying to the user and the one that contains the button handling the event. So what you're actually doing is just create new A frame, do something with it, but since it's not the one that is displayed you can't see the result of the action. It's a variable local to that method in B class.

Why don't you declare method in class B to return a String (message that's to be appended to your JTextArea)? Invoke that method on object of B class from event handler in class A to get the message as String and append it where needed.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!