java Swing

Get new comments by email
You can cancel email alerts at anytime.
Comments (1)

kasiram.p@gmail.com in Hyderabad, India

48 months ago

And in my code, it is working fine, but when i click save as button, save as dialog pops up and if i give an already existing file name, it throws an error dialog as "File already exists, do you want to replace?' and if i click CANCEL, the save as dialog again pops up and if i give the same file name which is already existing, it saves, without giving error dialog, that 'File name already exist?'
<html>
<p>
map_saveas.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {

System.out.println(mainFrame.getTitle());
String title=mainFrame.getTitle();
String s5="";
if(title.indexOf("-")!=-1)
{
int Index=title.indexOf("-");
s5=title.substring(0, Index);
}
else
{
s5=mainFrame.getTitle();
}
File wrkDir = new File("c:/nis/Projects/"+s5+"/");
JFileChooser chooser = new JFileChooser();
setFileChooserFont(chooser.getComponents());
chooser.setCurrentDirectory(wrkDir);
chooser.setDialogTitle("Save As");
chooser.setAcceptAllFileFilterUsed(false);
chooser.setFileFilter(new SaveMapfilter());
int returnVal = chooser.showSaveDialog(null);
File fil=chooser.getSelectedFile();

String filename=fil.getName();

String newfilename;
int index=filename.indexOf(".");
System.out.println(index);
String filename1=fil.getName();
//String s=form.getText(0);
String s2=s5+"-"+filename1+".map";
setTitle(s2);

if(index==-1)
{
String s6="c:/nis/Projects/"+s5+"/"+filename;
File f = new File(s6);
try{
if(f.mkdir())
System.out.println("Directory Created");
else
System.out.println("Directory is not created");
}catch(Exception e5){
System.out.println(e5);
}
String sub=filename+".map";
newfilename=sub;
String s8="c:/nis/Projects/"+s5+"/"+filename+"/"+sub;
fil=new File(s8);

}else {

String sub1=filename.substring(0,index);
String sub2=sub1;
String s6="c:/nis/Projects/"+s5+"/"+sub2;
File f = new File(s6);
try{
if(f.mkdir())

- Was this comment helpful? Yes / No (2) Reply - Report abuse

» Sign in or create an account to comment on this topic.