In the following code there is a JTextArea with an initial string. When the user changes the text in the JTextArea and clicks on update on the menu bar, class2.update() is called which in turn calls a class1.getText() method which should return the text in the JTextArea. The problem I am having is that the inital string is always returned. For troubleshooting I added a line in the actionPerformed() method that calls the same class1.getText() method. However, this time the current contents of the text are returned. How do I get the class2.update() method to print the current contents of the JTextArea? Also, where are the initial contents of the JTextArea being stored so that they keep being returned in the update() method? The following code is a model of an application I am writing. If someone can help me understand what is happening here I will be able to apply it to my application.
(edited by Cindy to format code) [This message has been edited by Cindy Glass (edited June 18, 2001).]
Inside Class2, you make a new Class1 (which contains a TextField)
Inside Class3, you create a Class1 and a Class2. So how many textfields are there? Answer: two. One that is shown, because you add it (the textfield that is buried in Class1 is the one on the UI). The other is not shown on the UI, the one in Class2. This is the one you call update on... but it will not have the changed data. It still has the original, untouched (and untouchable, since it's not on the UI) value of "Text Area".
Try this code and see what I mean:
Joined: Jun 18, 2001
Thanks for the help, Mike. I am new to object-oriented programming. It was a lot easier to fix my code than I thought it would be. I just removed the line in Class3 that creates a Class1 object and then referenced class2.class1. Works beautifully!