Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

appending message in TextArea

 
Scott A Burch
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!
 
Kemal Sokolovic
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