0

I have two classes, one does something like this:

public ClassOne:

package classes;
    public class ClassOne {
        public javax.swing.JTextArea progressListing
        progressListing = new javax.swing.JTextArea();
        public void files(File file){
        Class method = new Class();
        method.methodInOtherClass(files);
        }

        public void progressUpdate (String fileOutput){
        progressListing.insert(fileOutput,0);
        }
    }

which then goes to the other class that has the following: Other Class:

package classes;
    public class OtherClass extends ClassOne{
        public void methodInOtherClass(file){
        String fileOutput
        fileOutput = file.getName();
        ClassOne input = new ClassOne();
        input.progressUpdate(fileOutput);
        }
    }

It is not updating the progessListing field when the program runs. Is there a better way to do this or am I missing something?

What OtherClass does is it creates pdf files that need to show up in the text area(ie the file path with the file name). ClassOne is the swing interface. Even when it's extended into the other class it doesn't modify the text field when I need it to.

TomMonTom
  • 45
  • 7
  • I think that you decided to change your code in order to help us know what you're trying to do. Please put your original code. We can't understand what is: `methodInOtherClass()` – roeygol Jan 27 '15 at 17:51
  • You're creating new instance of ClassOne each time you call methodInOtherClass instead of calling of from original instance, of course it is not updating! – ancalled Jan 27 '15 at 17:59
  • `ClassOne input = new ClassOne();` this creates a separate instance of `ClassOne` than the one that called the method. This is basic OOP and should be well understood before attempting writing a GUI, which is an advanced topic. – Andrew Thompson Jan 27 '15 at 18:16
  • Would a setter and getter method work better to pass the information from the other class to class one? I just need to pass a string that is in a for loop. I'll post later on what I'm talking about. – TomMonTom Jan 27 '15 at 21:48
  • Try one of the approaches examined in this possible [duplicate](http://stackoverflow.com/q/25526833/230513), for [example](http://stackoverflow.com/a/26854330/230513). – trashgod Jan 27 '15 at 22:15

2 Answers2

0

Correct me if I'm wrong, but looking at the code you have posted, I think that you are trying to read a file and put the data from the file into the text area. Again, please correct me if I'm wrong. I think you should use the following code:

BufferedReader br = new BufferedReader(new FileReader("fileName.txt");
String data = br.readLine();
jTextArea1.append("\n"+data);

Please tell me if it works.

Cheers.

PS. If you post your whole code I will be able to help better.

nom
  • 256
  • 3
  • 16
  • It didn't work unfortunately. The files are generated automatically with a string. I just need to pass the string from the other class to the main class. – TomMonTom Jan 28 '15 at 05:14
0

I figured it out. I used a getter method in the other class to assign the variable and returned it to the main class. I set the String inside the loop to have an assign and add function. Works like a charm.

TomMonTom
  • 45
  • 7