I am trying to understand how the following code ties into two other .java files that are in the package template. In the main method are three class being instantiated? Why put them in the main method if everything is in the package template? Will these all have Driver class as a superclass? And finally are any of the words in the three classes that are being instantiated java specific words with the exception of the work “new”. Thanks for any insight into this. I am trying to understand how a project fits together so that I can write a recursive algorithm to search files. Thank you
One more question I want to make sure that I understand is why is gui in the parameter for DirectoryLister….DirectoryLister(gui);??? Does it need to be there in the main class so that it can call methods from gui??
package template;
import javax.swing.*;
public class Driver
{
public static void main(String[] args)
{
GUI gui = new GUI();
DirectoryLister dl = new DirectoryLister(gui);
gui.registerModel(dl);
}
}
Lot of questions:
No, only two are explicitly instantiated:
GUIandDirectoryLister.mainmethod is just the entry point for your program. You may or may not put everything insidemainmethod. Just keep in mind that that’s where your program will start executing.If you are referring to
GUIandDirectoryListerthen the answer is NO. Not at all. They’re completely independent.No. None of them.
DirectoryListerprobably expects aGUIinstance in one of its constructors. You are building yourdlobject withguielement by callingDirectoryLister(GUI g)constructor.—
Also, keep in mind that your question is not related to JavaME as you tagged it. It’s just a plain Java question. You won’t be using JavaME here since you are importing
javax.swing.*which is not available for JavaME edition.