Hello,
My assignment in class is to write a notepad program in java, using only the .io and .awt extensions (I believe that's what they're called). Now, I've got every part of the program working, except the save and saveAs functions. I've spent roughly 5 hours looking for and trying things that would solve my problem, but have found nothing (This professor doesn't really teach java, he teaches from the glossary, so it's become a learning experience in itself). the code I have so far is taken from the web, and I have modified it a bit to suit my program. I've gotten to the realization that it's not actually saving, and it doesnt know where to save to, and that's where I'm at a loss. How might I get that to change? Code is as follors for the two functions:
private void doSaveAs() {
StringBuffer textBuffer = new StringBuffer();
FileDialog fileDialog = new FileDialog(new Frame(), "Save", FileDialog.SAVE);
String name = fileDialog.getFile();
fileDialog.setFilenameFilter(new FilenameFilter() {
public boolean accept(File dir, String name) {
return name.endsWith(".txt");
}
});
fileDialog.setFile("Untitled.txt");
fileDialog.setVisible(true);
System.out.println("File: " + fileDialog.getFile());
setTitle("JavaEdit: " +name); // reset frame title
text.setText(textBuffer.toString());
}
private void doSave() {
FileDialog fileDialog = new FileDialog(new Frame(), "Save", FileDialog.SAVE);
String name = fileDialog.getFile();
if(name == null)
{
doSaveAs();
}
else{
System.out.println("File: " + fileDialog.getFile());
}
}
Also, I'm not sure, but I do believe the normal save function brings up the dialog box. How I would I hypothetically have that not happen?
Thanks for your time