I created a class A that reads a text file and alters some lines within the text, and the code is written in main() of this class. I also created another class B that has a Frame, the Frame contains a list of text files of a directory and a button. What I don’t know how to do is this: When I click on the selected item on the list and click the button, the function main is called and the selected item is being read by main().
Any suggestion is welcomed and thanks in advance.
When you have code in the static main method, you have a non-object oriented code block, one that won’t easily be used by other object oriented-compliant portions of your program. The best solution here is to get all code but the minimal out of main and create a true OOP-compliant class, one that can be more easily used by your other classes.
Your other issue is the mixing of your text-processing code with your GUI code, and this may require further fixing, especially if the text-processing code takes a while to complete or is a CPU hog. If so, you’ll need to take care to do the text-processing in a thread that is background to the GUI thread, and again, this is much more easily performed if the text-processing code is in a well-behaved OOP class.