Insert the following new method there:
/** * Update the caption of the application to show the filename and its dirty state. */ void updateCaption() { String caption; if (currFileName == null) { // synthesize the "Untitled" name if no name yet. caption = "Untitled"; } else { caption = currFileName; } // add a "*" in the caption if the file is dirty. if (dirty) { caption = "* " + caption; } caption = "TextEdit - " + caption; this.setTitle(caption); }
Specifically, put the call updateCaption();
in the following places:
this.dirty=false
in the try block of saveFile().
menuItem1_actionPerformed()
.
textArea1_textChangedValue
event handler, which should be changed to read:
void textArea1_textValueChanged(java.awt.event.TextEvent e) { if (!dirty) { dirty = true; updateCaption(); } }