Changing GUI component from another class while method is executed

Hello,

I have two classes, GUI class called MainFrame and MyZip class which archives all files and sub folders.

The GUI class calls the method doZip from MyZip class and parses the source file and destination file.

What I am trying to do, is to get a list of already archived files while doZip method is executing. Basically after completing every file it should parse the file name to the GUI class so I will be able to change the JTextArea and add this file name to the bottom of the list.

I assume it should be done using threads, but I don't really know how.

[597 byte] By [npocmoa] at [2007-11-27 7:06:30]
# 1
I'm not entirely sure what you're trying to do, but it sounds like maybe it should be done with callbacks.Every time MyZip zips up an individual file, it will call a method called, say, reportZipFile on the MainFrame class, and that class would append the name on the text area.
paulcwa at 2007-7-12 18:57:49 > top of Java-index,Java Essentials,Java Programming...
# 2
I tried to do like this, but there is a problem to call non static method from another class, but if I will define reportZipFile as static it will cause problems in my MainFrame class.
npocmoa at 2007-7-12 18:57:49 > top of Java-index,Java Essentials,Java Programming...
# 3

I am thinking to create in MyZip class a vector or array of file names where new file name will be added after completion, and method getZippedFileNames which will parse this vector and erase it's content.

So the idea is that I'll launch my doZip method from main() in one thread and then I will call for example every second method getZippedFileNames.

But I am not sure this is the way normal programmers do :)

npocmoa at 2007-7-12 18:57:49 > top of Java-index,Java Essentials,Java Programming...
# 4

When you call doZip, pass it an instance of another class. This other class will have the reportZipFile method. reportZipFile could be declared as a method in an interface. Then MainFrame could implement that interface, and it would pass itself over doZip.

Then doZip will hold the reference to that object, and invoke its reportZipFile method as needed.

You'll probably need to refactor doZip to support this. No big deal.

Generally, you should avoid static methods. They have their uses, but they tend to be overused by people who aren't comfortable yet with object oriented programming.

paulcwa at 2007-7-12 18:57:49 > top of Java-index,Java Essentials,Java Programming...