Modifications and advice for Project 6 are listed here in reverse chronological order, with new additions at the top.
The handout, under Other Specs, states the following: "For all questions requiring yes/no answers use JOptionPane.showInputDialog()" and "For all text inputs (such as reading in the file name) use JOptionPane.showInputDialog()".
The idea was that you would implement everything as a graphical user interface. A student pointed out that this would require you to rewrite FileUtils.java, in which the code for file-access-checking and prompting-for-new-filenames is intertwined.
If you are able to rewrite this code and successfully implement this functionality using dialog boxes, that would be fine. Perhaps we will give an extra credit point.
However, it is also fine if use FileUtils.java as it is, and if you implement the file-access-checking and the prompting-for-new-filenames from the command line. This would result in a partly-GUI and partly-command-line interface, which might not be ideal but would be fine as an intermediary version during product development. We will accept it here.
Note, however, that you may encounter some difficulty or awkwardness if you try to use modelToStringList() and stringListToFile() as we have been doing in previous Pn.java files. P5.java, for example, includes the following flow of control:
... // Run the simulation. controller.run(); // After the simulation, make sure the stringList is cleared. stringList.clear(); // Save the model to the stringList. MaritimeModel.modelToStringList(stringList); // Save the stringList into the file. FileUtils.stringListToFile(stringList, fileName); ...
You might think that, in P6.java, you could just replace
controller.run();
with
new View();
which would create and start the JFrame associated with the simulation (seeing as how View extends JFrame). You might think that, when you close the JFrame, you'll continue with the next line in main(), converting the model to ArrayList, and then saving ArrayList to a file.
The problem is that the JFrame evidently gets created in a new "thread," which means that one flow of control gets handed over to the JFrame but a separate flow of control continues executing the code in P6.java. The prompt to overwrite world.txt, for example, would probably appear at the same time as the JFrame.
One potential solution to this problem would be to call these two methods, modelToStringList() and stringListToFile(), from inside Controller.java as soon as the user types the "quit" command. The quit command could also trigger the closing of the window. Yes, it will be awkward if the prompts appear in the command line window instead of the GUI. It will also be awkward if the command line window could be hidden behind the View JFrame, but this would all be acceptable for this project. You may need to create a try-catch block within Controller.java in order to accomplish this.
You will also have to deal with the potential closing of the JFrame by clicking in the 'close window' button. This should also ideally prompt the user to save the file.
The project assignment offers this advice for creating MapPanel: "Don't forget to call the super.paint method before you start drawing your stuff." It turns out that this is not necessary.