1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
|
if (source==Save)
{
try{
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}catch(Exception exc) {System.err.println("Error loading L&F: "+exc);}
boolean test,testb;
JFileChooser filechooser = new JFileChooser();
filechooser.setAcceptAllFileFilterUsed(false);
filechooser.addChoosableFileFilter(serFilter);
testb=true;
while(testb==true)
{
int choix = filechooser.showSaveDialog(this); //display saving window
if(choix == JFileChooser.APPROVE_OPTION)
{
v.fil = filechooser.getSelectedFile()+".ser"; //get selected file
test=v.fil.endsWith(".ser.ser");
filechooser.setDialogTitle("Save PRA");
//filechooser.setSelectedFile(null);
if(!(v.fil.endsWith(".ser")))
{
testb=false;
JOptionPane.showMessageDialog(null,"Wrong File Format","Warning",JOptionPane.INFORMATION_MESSAGE);
}
if(test==true&&testb!=false)
{
int le=v.fil.length();
int rep=JOptionPane.showConfirmDialog(null,filechooser.getSelectedFile()+" already exist. Do you want to replace it?","Warning",JOptionPane.YES_NO_OPTION);
//filechooser.setSelectedFile(null);
if(rep==0)
{
v.fil=v.fil.substring(0,le-4);
new Save(v.fil,v);
testb=false;
JOptionPane.showMessageDialog(null,"Save done","Warning",JOptionPane.INFORMATION_MESSAGE);
}
}
if(test==false&&testb!=false)
{
new Save(v.fil,v);
testb=false;
JOptionPane.showMessageDialog(null,"Save done","Warning",JOptionPane.INFORMATION_MESSAGE);
}
}
else testb=false;
}
try{
UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
}catch(Exception exc) {System.err.println("Error loading L&F: "+exc);}
} |
Partager