Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
  • Piet Souris
  • Himai Minh

Handling menu events

Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear all,
i have created a text editor with menus as those given in a notepad application. i have created the following codes on how to save a file.
FileDialog fd2 = new FileDialog (this, "Save file", FileDialog.SAVE);
FileWriter fw;
String st,sn;
sn= nt.fd2.getDirectory()+"/"+nt.fd2.getFile()+".txt";
fw = new FileWriter(sn);
char ch;
String stt=nt.t.getText();
for(int i=0;i<stt.length();i++)

catch(FileNotFoundException ee){}
catch(IOException eee){}

but everytime i click on the save menu the save as dialog box appears even though the file has been saved already, can anyone help me out with the code so that if the file has been saved already the 'save as' dialog box should not reappear but just save the latest changes made.
Ranch Hand
Posts: 264
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Couple of things:
1. You can do it by saving the file name in a member variable in the class and modifying the code like:

In this case, the file dialog will not open if fileName is already set.
2. You might want to code a bit cleaner (Sorry if im being rude).
Acetylsalicylic acid is aspirin. This could be handy too:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
    Bookmark Topic Watch Topic
  • New Topic