FileDocCategorySizeDatePackage
AutoSave.javaAPI DocExample3795Sat Mar 13 20:03:48 GMT 2004None

AutoSave

public class AutoSave extends Thread
Demonstration of using a Thread to automatically save the user's work periodically.

Fields Summary
protected FileSaver
model
The FileSave interface is implemented by the main class.
public static final int
MINUTES
How long to sleep between tries
private static final int
SECONDS
Constructors Summary
public AutoSave(FileSaver m)


	   
		super("AutoSave Thread");
		setDaemon(true);		// so we don't keep the main app alive
		model = m;
	
Methods Summary
public voidrun()

		while (true) {		// entire run method runs forever.
			try {
				sleep(SECONDS*1000);
			} catch (InterruptedException e) {
				// do nothing with it
			}
			if (model.wantAutoSave() && model.hasUnsavedChanges())
				model.saveFile(null);
		}