當前位置: 首頁>>代碼示例>>Java>>正文


Java FileDialog.getDirectory方法代碼示例

本文整理匯總了Java中java.awt.FileDialog.getDirectory方法的典型用法代碼示例。如果您正苦於以下問題:Java FileDialog.getDirectory方法的具體用法?Java FileDialog.getDirectory怎麽用?Java FileDialog.getDirectory使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.awt.FileDialog的用法示例。


在下文中一共展示了FileDialog.getDirectory方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: showFileDialog

import java.awt.FileDialog; //導入方法依賴的package包/類
private File showFileDialog( FileDialog fileDialog, int mode ) {
    String oldFileDialogProp = System.getProperty("apple.awt.fileDialogForDirectories"); //NOI18N
    if( dirsOnly ) {
        System.setProperty("apple.awt.fileDialogForDirectories", "true"); //NOI18N
    }
    fileDialog.setMode( mode );
    fileDialog.setVisible(true);
    if( dirsOnly ) {
        if( null != oldFileDialogProp ) {
            System.setProperty("apple.awt.fileDialogForDirectories", oldFileDialogProp); //NOI18N
        } else {
            System.clearProperty("apple.awt.fileDialogForDirectories"); //NOI18N
        }
    }
    if( fileDialog.getDirectory() != null && fileDialog.getFile() != null ) {
        String selFile = fileDialog.getFile();
        File dir = new File( fileDialog.getDirectory() );
        return new File( dir, selFile );
    }
    return null;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:22,代碼來源:FileChooserBuilder.java

示例2: showSaveDialog

import java.awt.FileDialog; //導入方法依賴的package包/類
public int showSaveDialog(Component parent) {
  final FileDialog fd = awt_file_dialog_init(parent);
  fd.setMode(FileDialog.SAVE);
  fd.setVisible(true);

  final int value;
  if (fd.getFile() != null) {
    cur = new File(fd.getDirectory(), fd.getFile());
    value = FileChooser.APPROVE_OPTION;
  }
  else {
    value = FileChooser.CANCEL_OPTION;
  }
  updateDirectoryPreference();
  return value;
}
 
開發者ID:ajmath,項目名稱:VASSAL-src,代碼行數:17,代碼來源:FileChooser.java

示例3: showOpenDialog

import java.awt.FileDialog; //導入方法依賴的package包/類
public int showOpenDialog(Component parent) {
  final FileDialog fd = awt_file_dialog_init(parent);
  fd.setMode(FileDialog.LOAD);
  System.setProperty("apple.awt.fileDialogForDirectories",
                     String.valueOf(mode == DIRECTORIES_ONLY));
  fd.setVisible(true);

  final int value;
  if (fd.getFile() != null) {
    cur = new File(fd.getDirectory(), fd.getFile());
    value = FileChooser.APPROVE_OPTION;
  }
  else {
    value = FileChooser.CANCEL_OPTION;
  }
  updateDirectoryPreference();
  return value;
}
 
開發者ID:ajmath,項目名稱:VASSAL-src,代碼行數:19,代碼來源:FileChooser.java

示例4: 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;
}
 
開發者ID:addertheblack,項目名稱:myster,代碼行數:22,代碼來源:DownloaderThread.java

示例5: create

import java.awt.FileDialog; //導入方法依賴的package包/類
public static KeyStoreEditor create(Frame parentWindow) {
	KeyStoreEditor editor = new KeyStoreEditor();
	String dialogTitle = "Create Keystore";
	Icon icon = QDialog.getIcon(QDialog.PLAIN_MESSAGE);
	QDialog.showDialog(parentWindow, dialogTitle, icon, editor, editor.footer, true, null, null);
	JComponent button = editor.footer.getLastSelectedComponent();
	if( button==editor.footer.getButton(DialogFooter.OK_OPTION) ) {
		FileDialog fd = new FileDialog(parentWindow, "Create Keystore", FileDialog.SAVE);
		fd.setFilenameFilter(new SuffixFilenameFilter("jks"));
		fd.setFile("keystore.jks");
		fd.pack();
		fd.setLocationRelativeTo(null);
		fd.setVisible(true);
		if(fd.getFile()==null)
			return null;
		editor.jksFile = new File(fd.getDirectory()+fd.getFile());
		editor.create(false);
		return editor;
	} else {
		return null;
	}
}
 
開發者ID:mickleness,項目名稱:pumpernickel,代碼行數:23,代碼來源:KeyStoreEditor.java

示例6: actionPerformed

import java.awt.FileDialog; //導入方法依賴的package包/類
public void actionPerformed(ActionEvent event) {
	if (panel.getGameState() == GameState.INITIALIZE) {
		JOptionPane.showConfirmDialog(SnakeGameFrame.this,
						"��Ϸû������\n���ܱ�����Ϸ����", "̰������Ϸ",
						JOptionPane.DEFAULT_OPTION);
		return;
	}

	FileDialog dialog = new FileDialog(SnakeGameFrame.this, "Save",FileDialog.SAVE);
	dialog.setVisible(true);
	String dir = dialog.getDirectory();
	String fileName = dialog.getFile();//��ȡ����������������ġ�Ҫ������ļ�����
	String filePath = dir + fileName;
	if (fileName != null && fileName.trim().length() != 0) {
		File file = new File(filePath);
		panel.saveGameDataToFile(file);
	} else {
		JOptionPane.showConfirmDialog(SnakeGameFrame.this,
				"�ļ���Ϊ��\n������Ϸ����ʧ��", "̰������Ϸ", JOptionPane.DEFAULT_OPTION);
	}

}
 
開發者ID:ljheee,項目名稱:MySnakeGame,代碼行數:23,代碼來源:SnakeGameFrame.java

示例7: actionPerformed

import java.awt.FileDialog; //導入方法依賴的package包/類
@Override
public void actionPerformed(ActionEvent e) {
    FileDialog fileDialog = new FileDialog(ImageViewerGui.getMainFrame(), "Choose a file", FileDialog.LOAD);
    // does not work on Windows
    fileDialog.setFilenameFilter(new AllFilenameFilter());
    fileDialog.setMultipleMode(true);
    fileDialog.setDirectory(Settings.getSingletonInstance().getProperty("default.local.path"));
    fileDialog.setVisible(true);

    String directory = fileDialog.getDirectory();
    File[] fileNames = fileDialog.getFiles();
    if (fileNames.length > 0 && directory != null) {
        // remember the current directory for future
        Settings.getSingletonInstance().setProperty("default.local.path", directory);
        Settings.getSingletonInstance().save("default.local.path");
        for (File fileName : fileNames) {
            if (fileName.isFile())
                Load.image.get(fileName.toURI());
        }
    }
}
 
開發者ID:Helioviewer-Project,項目名稱:JHelioviewer-SWHV,代碼行數:22,代碼來源:OpenLocalFileAction.java

示例8: browseForFile

import java.awt.FileDialog; //導入方法依賴的package包/類
/** If invoked from within a Frame: this pulls up a FileDialog to
 * browse for a file. If this is invoked from a secure applet: then
 * this will throw an exception.
 * 
 * @param ext an optional list of extensions
 * @return a File, or null if the user declined to select anything.
 */
public File browseForFile(String... ext) {
	Window w = SwingUtilities.getWindowAncestor(this);
	if(!(w instanceof Frame))
		throw new IllegalStateException();
	Frame frame = (Frame)w;
	FileDialog fd = new FileDialog(frame);
	if(ext!=null && ext.length>0 && (!(ext.length==1 && ext[0]==null)))
		fd.setFilenameFilter(new SuffixFilenameFilter(ext));
	fd.pack();
	fd.setLocationRelativeTo(null);
	fd.setVisible(true);
	String d = fd.getFile();
	if(d==null) return null;
	return new File(fd.getDirectory()+fd.getFile());
}
 
開發者ID:mickleness,項目名稱:pumpernickel,代碼行數:23,代碼來源:ImageQuantizationDemo.java

示例9: main

import java.awt.FileDialog; //導入方法依賴的package包/類
@SuppressWarnings("unused")
private static void main(String[] s) {
	try {
		JFrame frame = new JFrame();
		FileDialog fd = new FileDialog(frame);
		fd.setFilenameFilter(new SuffixFilenameFilter("wav", "wave"));
		fd.pack();
		fd.setVisible(true);
		if(fd.getFile()==null) return;
		File wavFile = new File(fd.getDirectory()+fd.getFile());
		FileInputStream in = null;
		try {
			in = new FileInputStream(wavFile);
			System.err.println("length: " + wavFile.length());
			WavCopier r = new WavCopier(in);
		} finally {
			in.close();
		}
		System.exit(0);
	} catch(IOException e) {
		e.printStackTrace();
		System.exit(1);
	}
}
 
開發者ID:mickleness,項目名稱:pumpernickel,代碼行數:25,代碼來源:WavCopier.java

示例10: 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;
}
 
開發者ID:nativelibs4java,項目名稱:JavaCL,代碼行數:22,代碼來源:Utils.java

示例11: doUtteranceLoadFile

import java.awt.FileDialog; //導入方法依賴的package包/類
protected void doUtteranceLoadFile()
{
    FileDialog fd = new FileDialog(getFrame(), "Load Utterance File", FileDialog.LOAD);
    fd.setDirectory(RuntimeLogic.getProp("utterance.file.dir"));
    fd.setFile(RuntimeLogic.getProp("utterance.file.file"));
    fd.setVisible(true);
    if (fd.getDirectory() == null)
        return;
    String intentFile = fd.getDirectory()+System.getProperty("file.separator")+fd.getFile();
    if ((intentFile == null) || (intentFile.length() == 0))
        return;
    try
    {
        RuntimeLogic.readUtterances(mRuntime, (new File(intentFile)).toURI());
        RuntimeLogic.setProp("utterance.file.dir", fd.getDirectory());
        RuntimeLogic.setProp("utterance.file.file", fd.getFile());
    }
    catch (IOException e)
    {
        JOptionPane.showMessageDialog(this, e.getLocalizedMessage(), "Error reading "+intentFile, JOptionPane.ERROR_MESSAGE);
    }
}
 
開發者ID:jjaquinta,項目名稱:EchoSim,代碼行數:23,代碼來源:ApplicationPanel.java

示例12: doSave

import java.awt.FileDialog; //導入方法依賴的package包/類
private void doSave()
{
    FileDialog fd = new FileDialog(getFrame(), "Save History File", FileDialog.SAVE);
    fd.setDirectory(RuntimeLogic.getProp("history.file.dir"));
    fd.setFile(RuntimeLogic.getProp("history.file.file"));
    fd.setVisible(true);
    if (fd.getDirectory() == null)
        return;
    String historyFile = fd.getDirectory()+System.getProperty("file.separator")+fd.getFile();
    if ((historyFile == null) || (historyFile.length() == 0))
        return;
    try
    {
        RuntimeLogic.saveHistory(mRuntime, new File(historyFile));
        RuntimeLogic.setProp("history.file.dir", fd.getDirectory());
        RuntimeLogic.setProp("history.file.file", fd.getFile());
    }
    catch (IOException e)
    {
        JOptionPane.showMessageDialog(this, e.getLocalizedMessage(), "Error reading "+historyFile, JOptionPane.ERROR_MESSAGE);
    }
}
 
開發者ID:jjaquinta,項目名稱:EchoSim,代碼行數:23,代碼來源:TestingPanel.java

示例13: doSaveDisk

import java.awt.FileDialog; //導入方法依賴的package包/類
private void doSaveDisk()
{
    FileDialog fd = new FileDialog(getFrame(), "Save Suite", FileDialog.SAVE);
    fd.setDirectory(RuntimeLogic.getProp("suite.file.dir"));
    fd.setFile(RuntimeLogic.getProp("suite.file.file"));
    fd.setVisible(true);
    if (fd.getDirectory() == null)
        return;
    String historyFile = fd.getDirectory()+System.getProperty("file.separator")+fd.getFile();
    if ((historyFile == null) || (historyFile.length() == 0))
        return;
    try
    {
        SuiteLogic.save(mRuntime, new File(historyFile));
        RuntimeLogic.setProp("suite.file.dir", fd.getDirectory());
        RuntimeLogic.setProp("suite.file.file", fd.getFile());
    }
    catch (IOException e)
    {
        JOptionPane.showMessageDialog(this, e.getLocalizedMessage(), "Error reading "+historyFile, JOptionPane.ERROR_MESSAGE);
    }
}
 
開發者ID:jjaquinta,項目名稱:EchoSim,代碼行數:23,代碼來源:SuitePanel.java

示例14: 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);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:28,代碼來源:Ted.java

示例15: 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);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:10,代碼來源:Ted.java


注:本文中的java.awt.FileDialog.getDirectory方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。