public void newDomain(){
  JFileChooser fileChooser=new JFileChooser(System.getProperty("user.dir"));
  fileChooser.setDialogTitle("Save the new domain in file ...");
  fileChooser.setFileFilter(new FileNameExtensionFilter("XML file","xml"));
  if (fileChooser.showSaveDialog(frame) == JFileChooser.APPROVE_OPTION) {
    File fileToSave=fileChooser.getSelectedFile();
    if (fileToSave.exists()) {
      int result=JOptionPane.showConfirmDialog(frame,"The file exists, overwrite?","Existing file",JOptionPane.YES_NO_CANCEL_OPTION);
      if (result == JOptionPane.NO_OPTION || result == JOptionPane.CLOSED_OPTION || result == JOptionPane.CANCEL_OPTION) {
        return;
      }
    }
    newDomain(fileToSave);
  }
}

public void newDomain ( ) { JFileChooser fileChooser = new JFileChooser ( System . getProperty ( "user.dir" ) ) ; fileChooser . setDialogTitle ( "Save the new domain in file ..." ) ; fileChooser . setFileFilter ( new FileNameExtensionFilter ( "XML file" , "xml" ) ) ; if ( fileChooser . showSaveDialog ( frame ) == JFileChooser . APPROVE_OPTION ) { File fileToSave = fileChooser . getSelectedFile ( ) ; if ( fileToSave . exists ( ) ) { int result = JOptionPane . showConfirmDialog ( frame , "The file exists, overwrite?" , "Existing file" , JOptionPane . YES_NO_CANCEL_OPTION ) ; if ( result == JOptionPane . NO_OPTION || result == JOptionPane . CLOSED_OPTION || result == JOptionPane . CANCEL_OPTION ) { return ; } } newDomain ( fileToSave ) ; } }
creates a new domain
