本文整理匯總了Java中java.awt.FileDialog.show方法的典型用法代碼示例。如果您正苦於以下問題:Java FileDialog.show方法的具體用法?Java FileDialog.show怎麽用?Java FileDialog.show使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.awt.FileDialog
的用法示例。
在下文中一共展示了FileDialog.show方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: askUser
import java.awt.FileDialog; //導入方法依賴的package包/類
private static String[] askUser(ProgressWindow progress, String dp, String initialFileName, String a) {
String ask = (a == null ? "What do you want to call this file?" : a);
String[] s = new String[2];
FileDialog dialog = new FileDialog(progress, ask, FileDialog.SAVE);
dialog.setSize(400, 300);
dialog.setDirectory(dp);
dialog.setFile(initialFileName);
dialog.show();
String temppath = dialog.getDirectory();
String chosenFileName = dialog.getFile();
if (chosenFileName == null) {
progress.setText("User Cancelled", FileProgressWindow.BAR_1);
return null;
}
s[0] = temppath;
s[1] = chosenFileName;
return s;
}
示例2: chooseFile
import java.awt.FileDialog; //導入方法依賴的package包/類
public static File chooseFile(File initialFile, boolean load) {
if (isMac()) {
FileDialog d = new FileDialog((java.awt.Frame)null);
d.setMode(load ? FileDialog.LOAD : FileDialog.SAVE);
if (initialFile != null) {
d.setDirectory(initialFile.getParent());
d.setFile(initialFile.getName());
}
d.show();
String f = d.getFile();
if (f != null)
return new File(new File(d.getDirectory()), d.getFile());
} else {
JFileChooser chooser = new JFileChooser();
if (initialFile != null)
chooser.setSelectedFile(initialFile);
if ((load ? chooser.showOpenDialog(null) : chooser.showSaveDialog(null)) == JFileChooser.APPROVE_OPTION)
return chooser.getSelectedFile();
}
return null;
}
示例3: jMenuItem4ActionPerformed
import java.awt.FileDialog; //導入方法依賴的package包/類
private void jMenuItem4ActionPerformed (java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem4ActionPerformed
// Add your handling code here:
FileDialog fileDialog = new FileDialog (this, "Open...", FileDialog.LOAD);
fileDialog.show ();
if (fileDialog.getFile () == null)
return;
fileName = fileDialog.getDirectory () + File.separator + fileDialog.getFile ();
FileInputStream fis = null;
String str = null;
try {
fis = new FileInputStream (fileName);
int size = fis.available ();
byte[] bytes = new byte [size];
fis.read (bytes);
str = new String (bytes);
} catch (IOException e) {
} finally {
try {
fis.close ();
} catch (IOException e2) {
}
}
if (str != null)
textBox.setText (str);
}
示例4: doSaveAs
import java.awt.FileDialog; //導入方法依賴的package包/類
private void doSaveAs () {
FileDialog fileDialog = new FileDialog (this, "Save As...", FileDialog.SAVE);
fileDialog.show ();
if (fileDialog.getFile () == null)
return;
fileName = fileDialog.getDirectory () + File.separator + fileDialog.getFile ();
doSave (fileName);
}
示例5: saveAs
import java.awt.FileDialog; //導入方法依賴的package包/類
/** Invoker for the saveas action */
public void saveAs() {
Doc doc = getSelectedDoc();
if (doc == null) {
throw new NullPointerException ("no doc");
}
FileDialog fd = new FileDialog (MiniEdit.this, "Save as");
fd.setMode(fd.SAVE);
fd.show();
if (fd.getFile() != null) {
File nue = new File (fd.getDirectory() + fd.getFile());
try {
boolean success = nue.createNewFile();
if (success) {
FileWriter w = new FileWriter (nue);
doc.getTextPane().write(w);
file = nue;
documentTabs.setTitleAt(documentTabs.getSelectedIndex(), nue.getName());
documentTabs.setToolTipTextAt(documentTabs.getSelectedIndex(), nue.toString());
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
示例6: openMenuItemActionPerformed
import java.awt.FileDialog; //導入方法依賴的package包/類
/** This method is called when File -> Open menu item is invoked.
* It displays a dialog to choose the file to be opened and edited.
* @param evt ActionEvent instance passed from actionPerformed event.
*/
private void openMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_openMenuItemActionPerformed
FileDialog fileDialog = new FileDialog(this, "Open...", FileDialog.LOAD);
fileDialog.show();
if (fileDialog.getFile() == null)
return;
fileName = fileDialog.getDirectory() + File.separator + fileDialog.getFile();
FileInputStream fis = null;
String str = null;
try {
fis = new FileInputStream(fileName);
int size = fis.available();
byte[] bytes = new byte [size];
fis.read(bytes);
str = new String(bytes);
} catch (IOException e) {
} finally {
try {
fis.close();
} catch (IOException e2) {
}
}
if (str != null)
textBox.setText(str);
}
示例7: doSaveAs
import java.awt.FileDialog; //導入方法依賴的package包/類
/** Asks for a file name. then saves the current content of editor pane to the file.
*/
private void doSaveAs() {
FileDialog fileDialog = new FileDialog(this, "Save As...", FileDialog.SAVE);
fileDialog.show();
if (fileDialog.getFile() == null)
return;
fileName = fileDialog.getDirectory() + File.separator + fileDialog.getFile();
doSave(fileName);
}
示例8: loadFile
import java.awt.FileDialog; //導入方法依賴的package包/類
public String loadFile(Frame f, String title, String defDir, String fileType) {
FileDialog fd = new FileDialog(f, title, FileDialog.LOAD);
fd.setFile(fileType);
fd.setDirectory(defDir);
fd.setLocation(50, 50);
fd.show();
return fd.getDirectory()+fd.getFile();
}
示例9: saveFile
import java.awt.FileDialog; //導入方法依賴的package包/類
public String saveFile(Frame f, String title, String defDir, String fileType) {
FileDialog fd = new FileDialog(f, title, FileDialog.SAVE);
fd.setFile(fileType);
fd.setDirectory(defDir);
fd.setLocation(50, 50);
fd.show();
return fd.getDirectory()+fd.getFile();
}
示例10: rChooseFile
import java.awt.FileDialog; //導入方法依賴的package包/類
public String rChooseFile(Rengine re, int newFile) {
FileDialog fd = new FileDialog(new Frame(), (newFile==0)?"Select a file":"Select a new file", (newFile==0)?FileDialog.LOAD:FileDialog.SAVE);
fd.show();
String res=null;
if (fd.getDirectory()!=null) res=fd.getDirectory();
if (fd.getFile()!=null) res=(res==null)?fd.getFile():(res+fd.getFile());
return res;
}
示例11: exportTableToCSV
import java.awt.FileDialog; //導入方法依賴的package包/類
/**
* Export table to csv.
*
* @param table
* the table
* @param fieldNames
* the field names
* @throws UNISoNException
* the UNI so n exception
*/
@SuppressWarnings("deprecation")
public void exportTableToCSV(final JTable table, final Vector<String> fieldNames)
throws UNISoNException {
final FileDialog file = new FileDialog(new JFrame(), "Save CSV Network File",
FileDialog.SAVE);
final String CSV_FILE_SUFFIX = ".csv";
final String initialValue = "*" + CSV_FILE_SUFFIX;
file.setFile(initialValue); // set initial filename filter
file.setFilenameFilter((dir, name) -> {
if (name.endsWith(CSV_FILE_SUFFIX)) {
return true;
}
return false;
});
file.show(); // Blocks
String curFile = null;
curFile = file.getFile();
if ((curFile != null) && !curFile.equals(initialValue)) {
if (!curFile.endsWith(CSV_FILE_SUFFIX)) {
curFile += CSV_FILE_SUFFIX;
}
final String filename = file.getDirectory() + curFile;
this.exportTable(filename, table, fieldNames);
}
}
示例12: saveButtonActionPerformed
import java.awt.FileDialog; //導入方法依賴的package包/類
/**
* Save button action performed.
*
* @param evt
* the evt
*/
@SuppressWarnings({ "deprecation" })
private void saveButtonActionPerformed(final java.awt.event.ActionEvent evt) {// GEN-FIRST:event_saveButtonActionPerformed
final FileDialog file = new FileDialog(this.frame, "Save Pajek Network File",
FileDialog.SAVE);
final String initialValue = "*" + PajekPanel.PAJEK_NETWORK_FILE_SUFFIX;
file.setFile(initialValue); // set initial filename filter
file.setFilenameFilter((dir, name) -> {
if (name.endsWith(PajekPanel.PAJEK_NETWORK_FILE_SUFFIX)) {
return true;
}
return false;
});
file.show(); // Blocks
String curFile = null;
curFile = file.getFile();
if ((curFile != null) && !curFile.equals(initialValue)) {
if (!curFile.endsWith(PajekPanel.PAJEK_NETWORK_FILE_SUFFIX)) {
curFile += PajekPanel.PAJEK_NETWORK_FILE_SUFFIX;
}
final String filename = file.getDirectory() + curFile;
final File saveFile = new File(filename); // chooser.getSelectedFile();
final String fileName = saveFile.getAbsolutePath();
this.pajekFile.saveToFile(fileName);
this.showStatus("Saved file " + filename);
}
else {
this.showStatus("You cancelled.");
}
}
示例13: chooseFile
import java.awt.FileDialog; //導入方法依賴的package包/類
static File chooseFile() {
if (Platform.isMacOSX()) {
FileDialog d = new FileDialog((java.awt.Frame)null);
d.setMode(FileDialog.LOAD);
d.show();
String f = d.getFile();
if (f != null)
return new File(new File(d.getDirectory()), d.getFile());
} else {
JFileChooser chooser = new JFileChooser();
if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION)
return chooser.getSelectedFile();
}
return null;
}
示例14: opendialog
import java.awt.FileDialog; //導入方法依賴的package包/類
public synchronized void opendialog() throws IOException {
FileDialog fd = new FileDialog(this, "open djvu file", FileDialog.LOAD);
fd.setMultipleMode(true);
fd.show();
if (fd.getDirectory() != null) {
File files[] = fd.getFiles();
for (File file : files) {
FileSavePath.save(file.getPath());
String url;
url = "" + file.toURI().toURL();
url = url.substring(5, url.length());
String name = file.getName();
if (!curropen.contains(name)) {
name_url.put(name, url);
url_name.put(url, name);
curropen.add(name);
bookList.add(url);
openBookInNewTab(url, name);
} else {
tabbedPane.setSelectedIndex(tabbedPane.indexOfTab(name));
}
}
} else {
}
}