hi , i am developing one smart word processor in java siwng,for load and save operation am using filechossers.
i am supporting multiple documents also using tabbedpane.i want to do when typing something on the document and without save that we will close the application means i want to do the save operation here.
please help very urgent,
thanks in advance. by ashok
posted 7 years ago
> i am supporting multiple documents
depends on how many 'multiple' is.
here's a basic scenario for a single doc:
(class field) boolean dirtyData = false; - add a document listener to the doc - it's job is to make dirtyData = true; - in your save() method, include dirtyData = false; - set the default close operation of the frame to DO_NOTHING_ON_CLOSE - add a windowListener to the frame, and in windowClosing() check if dirtyData is true, if so, call save() (or ask user if save() wanted), then System.exit(0);
there was a recent-ish thread on this subject (past 4-6 weeks), with other options. a quick search of this forum should find it.