Posted By:
Rahi_Parsi
Posted On:
Thursday, June 13, 2002 10:05 AM
Well since you know how to create/use menus with AWT, the task is a simple matter of storing the previously used files in a list which will be read from a file when the application is launched, and updated when closed.
I would recommend the following:
public class UsedFiles extends Object implements Serializable
{ protected String filenames[]=null;
public UsedFiles(int size){ super(); filenames=new String[size];}
public UsedFiles(String fnames[])
{ super(); filenames=fnames;}
protected int VerifyIndex(int index)
{ int n=index;
if(index<0){ n=0;}
else if(index>filenames.length-1){ n=filenames.length-1;}
return n;
}
public int getFileCount(){ return filenames.length;}
public String getFileName(int index)
{ return filenames[VerifyIndex(index)];}
public void setFileName(String fname,int index)
{ filenames[VerifyIndex(index)]=fname;}
public static UsedFiles readList(InputStream instream) throws IOException
{ UsedFiles files=null;
ObjectInputStream obstream=new ObjectInputStream(instream);
files=(UsedFiles)(obstream.readObject());
objstream.close();
return files;
}
public static void writeList(OutputStream oustream,UsedFiles files) throws IOException
{ ObjectOutputStream obstream=new ObjectOutputStream(oustream);
obstream.writeObject(files);
obstream.flush();
obstream.close();
}
}
You would use the class like this:
UsedFiles files=UsedFiles.readList(new FileInputStream("files.dat"));
files.setFileName("essay.doc",2);
UsedFiles.writeList(new FileOutputStream("files.dat"),files);