java.awt.FileDialog.setFile()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(9.2k)|赞(0)|评价(0)|浏览(223)

本文整理了Java中java.awt.FileDialog.setFile()方法的一些代码示例,展示了FileDialog.setFile()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。FileDialog.setFile()方法的具体详情如下:
包路径:java.awt.FileDialog
类名称:FileDialog
方法名:setFile

FileDialog.setFile介绍

暂无

代码示例

代码示例来源:origin: libgdx/libgdx

public void actionPerformed (ActionEvent evt) {
    FileDialog dialog = new FileDialog(Hiero.this, "Save BMFont files", FileDialog.SAVE);
    dialog.setLocationRelativeTo(null);
    dialog.setFile("*.fnt");
    dialog.setDirectory(prefs.get("dir.savebm", ""));
    if (lastSaveBMFilename.length() > 0) {
      dialog.setFile(lastSaveBMFilename);
    } else if (lastOpenFilename.length() > 0) {
      dialog.setFile(lastOpenFilename.replace(".hiero", ".fnt"));
    }
    dialog.setVisible(true);
    if (dialog.getDirectory() != null) {
      prefs.put("dir.savebm", dialog.getDirectory());
    }
    String fileName = dialog.getFile();
    if (fileName == null) return;
    lastSaveBMFilename = fileName;
    saveBm(new File(dialog.getDirectory(), fileName));
  }
});

代码示例来源:origin: nodebox/nodebox

if (f.getParentFile() != null) {
  fileDialog.setDirectory(f.getParentFile().getPath());
  fileDialog.setFile(f.getName());
} else {
  NodeBoxDocument document = NodeBoxDocument.getCurrentDocument();
  fileDialog.setFile(pathName);

代码示例来源:origin: libgdx/libgdx

public void actionPerformed (ActionEvent evt) {
    FileDialog dialog = new FileDialog(Hiero.this, "Save BMFont files", FileDialog.SAVE);
    dialog.setLocationRelativeTo(null);
    dialog.setFile("*.fnt");
    dialog.setDirectory(prefs.get("dir.savebm", ""));
    if (lastSaveBMFilename.length() > 0) {
      dialog.setFile(lastSaveBMFilename);
    } else if (lastOpenFilename.length() > 0) {
      dialog.setFile(lastOpenFilename.replace(".hiero", ".fnt"));
    }
    dialog.setVisible(true);
    if (dialog.getDirectory() != null) {
      prefs.put("dir.savebm", dialog.getDirectory());
    }
    String fileName = dialog.getFile();
    if (fileName == null) return;
    lastSaveBMFilename = fileName;
    saveBm(new File(dialog.getDirectory(), fileName));
  }
});

代码示例来源:origin: libgdx/libgdx

public void actionPerformed (ActionEvent evt) {
    FileDialog dialog = new FileDialog(Hiero.this, "Save Hiero settings file", FileDialog.SAVE);
    dialog.setLocationRelativeTo(null);
    dialog.setFile("*.hiero");
    dialog.setDirectory(prefs.get("dir.save", ""));
    if (lastSaveFilename.length() > 0) {
      dialog.setFile(lastSaveFilename);
    } else if (lastOpenFilename.length() > 0) {
      dialog.setFile(lastOpenFilename);
    }
    dialog.setVisible(true);
    if (dialog.getDirectory() != null) {
      prefs.put("dir.save", dialog.getDirectory());
    }
    String fileName = dialog.getFile();
    if (fileName == null) return;
    if (!fileName.endsWith(".hiero")) fileName += ".hiero";
    lastSaveFilename = fileName;
    File file = new File(dialog.getDirectory(), fileName);
    try {
      save(file);
    } catch (IOException ex) {
      throw new RuntimeException("Error saving Hiero settings file: " + file.getAbsolutePath(), ex);
    }
  }
});

代码示例来源:origin: libgdx/libgdx

public void actionPerformed (ActionEvent evt) {
    FileDialog dialog = new FileDialog(Hiero.this, "Save Hiero settings file", FileDialog.SAVE);
    dialog.setLocationRelativeTo(null);
    dialog.setFile("*.hiero");
    dialog.setDirectory(prefs.get("dir.save", ""));
    if (lastSaveFilename.length() > 0) {
      dialog.setFile(lastSaveFilename);
    } else if (lastOpenFilename.length() > 0) {
      dialog.setFile(lastOpenFilename);
    }
    dialog.setVisible(true);
    if (dialog.getDirectory() != null) {
      prefs.put("dir.save", dialog.getDirectory());
    }
    String fileName = dialog.getFile();
    if (fileName == null) return;
    if (!fileName.endsWith(".hiero")) fileName += ".hiero";
    lastSaveFilename = fileName;
    File file = new File(dialog.getDirectory(), fileName);
    try {
      save(file);
    } catch (IOException ex) {
      throw new RuntimeException("Error saving Hiero settings file: " + file.getAbsolutePath(), ex);
    }
  }
});

代码示例来源:origin: libgdx/libgdx

public void actionPerformed (ActionEvent evt) {
    FileDialog dialog = new FileDialog(Hiero.this, "Choose TrueType font file", FileDialog.LOAD);
    dialog.setLocationRelativeTo(null);
    dialog.setFile("*.ttf");
    dialog.setDirectory(prefs.get("dir.font", ""));
    dialog.setVisible(true);
    if (dialog.getDirectory() != null) {
      prefs.put("dir.font", dialog.getDirectory());
    }
    String fileName = dialog.getFile();
    if (fileName == null) return;
    fontFileText.setText(new File(dialog.getDirectory(), fileName).getAbsolutePath());
  }
});

代码示例来源:origin: libgdx/libgdx

public void actionPerformed (ActionEvent evt) {
    FileDialog dialog = new FileDialog(Hiero.this, "Choose TrueType font file", FileDialog.LOAD);
    dialog.setLocationRelativeTo(null);
    dialog.setFile("*.ttf");
    dialog.setDirectory(prefs.get("dir.font", ""));
    dialog.setVisible(true);
    if (dialog.getDirectory() != null) {
      prefs.put("dir.font", dialog.getDirectory());
    }
    String fileName = dialog.getFile();
    if (fileName == null) return;
    fontFileText.setText(new File(dialog.getDirectory(), fileName).getAbsolutePath());
  }
});

代码示例来源:origin: stackoverflow.com

FileDialog fd = new FileDialog(yourJFrame, "Choose a file", FileDialog.LOAD);
fd.setDirectory("C:\\");
fd.setFile("*.xml");
fd.setVisible(true);
String filename = fd.getFile();
if (filename == null)
 System.out.println("You cancelled the choice");
else
 System.out.println("You chose " + filename);

代码示例来源:origin: libgdx/libgdx

public void actionPerformed (ActionEvent evt) {
    FileDialog dialog = new FileDialog(Hiero.this, "Open Hiero settings file", FileDialog.LOAD);
    dialog.setLocationRelativeTo(null);
    dialog.setFile("*.hiero");
    dialog.setDirectory(prefs.get("dir.open", ""));
    dialog.setVisible(true);
    if (dialog.getDirectory() != null) {
      prefs.put("dir.open", dialog.getDirectory());
    }
    String fileName = dialog.getFile();
    if (fileName == null) return;
    lastOpenFilename = fileName;
    open(new File(dialog.getDirectory(), fileName));
  }
});

代码示例来源:origin: libgdx/libgdx

public void actionPerformed (ActionEvent evt) {
    FileDialog dialog = new FileDialog(Hiero.this, "Open Hiero settings file", FileDialog.LOAD);
    dialog.setLocationRelativeTo(null);
    dialog.setFile("*.hiero");
    dialog.setDirectory(prefs.get("dir.open", ""));
    dialog.setVisible(true);
    if (dialog.getDirectory() != null) {
      prefs.put("dir.open", dialog.getDirectory());
    }
    String fileName = dialog.getFile();
    if (fileName == null) return;
    lastOpenFilename = fileName;
    open(new File(dialog.getDirectory(), fileName));
  }
});

代码示例来源:origin: abbot/abbot

public void run() {
    dialog.setFile(file);
  }
});

代码示例来源:origin: abbot/abbot

public void windowClosed(WindowEvent e) {
    fd.setFile(file);
    fd.removeWindowListener(this);
  }
});

代码示例来源:origin: stackoverflow.com

FileDialog fd = new FileDialog((Frame) null, "Save File", FileDialog.SAVE);
fd.setFile("*.txt");
fd.setVisible(true);

String file = fd.getFile();
System.out.println(file);
System.exit(0);

代码示例来源:origin: stackoverflow.com

public void actionPerformed(ActionEvent e) {
     FileDialog saveFileDialog = new FileDialog(new Frame(), "Save", FileDialog.SAVE);
     saveFileDialog.setFile("*.jpg;*.jpeg");
     saveFileDialog.setVisible(true);
   }

代码示例来源:origin: stackoverflow.com

FileDialog fd = new FileDialog(parent, "Choose a file", FileDialog.LOAD);
fd.setDirectory("C:\\");
fd.setFile("*.java");
fd.setVisible(true);
String filename = fd.getFile();
if (filename == null)
 System.out.println("file not selected");
else
 System.out.println("You chose " + filename);

代码示例来源:origin: es.ucm.fdi.gaia/jCOLIBRI

public void actionPerformed(ActionEvent e)
{
  try{
    FileDialog fd = new FileDialog(dialog, "Save as CSV", FileDialog.SAVE);
    fd.setFile("evaluation.csv");
    fd.setVisible(true);
    String name = fd.getDirectory() + fd.getFile();
    File file = new File(name);
    saveEvaluationToCSV(evalReport, file);
  }
  catch(Exception ex) { 
    ex.printStackTrace(); 
  }                
}

代码示例来源:origin: jmtd/wadc

private void saveAs(ActionEvent e) {
 FileDialog fd = new FileDialog(this, __("save program (.wl)"), FileDialog.SAVE);
 fd.setDirectory((new File(prefs.get("basename"))).getParent());
 fd.setFile((new File(prefs.get("basename"))).getName()); //File f = new File(); f.
 fd.setVisible(true);
 String name = fd.getFile();
 if( name == null) {
  return;
 }
 prefs.put("basename", (new File(fd.getDirectory(),name)).toString());
 save(e);
}

代码示例来源:origin: org.appdapter/org.appdapter.lib.gui

void saveCollectionAs() {
  FileDialog dialog = new FileDialog(getFrame(), "Save " + getCollectionName(), FileDialog.SAVE);
  dialog.setFile("mycollection.ser");
  dialog.show();
  String fileName = dialog.getFile();
  String directory = dialog.getDirectory();
  theLogger.debug("fileName = " + fileName);
  theLogger.debug("directory = " + directory);
  if (fileName != null) {
    saveCollection(new File(directory, fileName));
  }
}

代码示例来源:origin: AliView/AliView

private void testFileDialog(){
  Frame f = new Frame();
  FileDialog fd = new FileDialog(f, "Hej", FileDialog.LOAD);
  fd.setDirectory("/home/anders/_ormbunkar");
  fd.setLocation(100,100);
  fd.setSize(600, 600);
  fd.setFile("");
  fd.setVisible(true);
  File selectedFile = new File(fd.getFile());
}

代码示例来源:origin: de.jflex/jflex

private void specChoose() {
  choosing = true;

  FileDialog d = new FileDialog(this, "Choose file", FileDialog.LOAD);

  d.setFile("*.flex");
  d.setVisible(true);

  if (d.getFile() != null) {
   fileName = d.getDirectory() + d.getFile();
   dir.setText(d.getDirectory());
   spec.setText(fileName);
  }

  choosing = false;
 }
}

相关文章