当前位置: 首页>>代码示例>>Java>>正文


Java FileDialog.getFile方法代码示例

本文整理汇总了Java中java.awt.FileDialog.getFile方法的典型用法代码示例。如果您正苦于以下问题:Java FileDialog.getFile方法的具体用法?Java FileDialog.getFile怎么用?Java FileDialog.getFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.awt.FileDialog的用法示例。


在下文中一共展示了FileDialog.getFile方法的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: actionPerformed

import java.awt.FileDialog; //导入方法依赖的package包/类
public void actionPerformed(ActionEvent event) {
	FileDialog dialog = new FileDialog(SnakeGameFrame.this, "Open",
			FileDialog.LOAD);
	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.loadGameDataFromFile(file);
		startMI.setEnabled(false);
		pauseMI.setEnabled(true);
	} else {
		JOptionPane.showConfirmDialog(SnakeGameFrame.this,
				"�ļ���Ϊ��\nװ����Ϸ����ʧ��", "̰������Ϸ", JOptionPane.DEFAULT_OPTION);
	}

}
 
开发者ID:ljheee,项目名称:MySnakeGame,代码行数:20,代码来源:SnakeGameFrame.java

示例6: showSaveDialog

import java.awt.FileDialog; //导入方法依赖的package包/类
public static File showSaveDialog(Frame f,String title,String extension) {
	if(extension.startsWith("."))
		extension = extension.substring(1);
	
	FileDialog fd = new FileDialog(f, title);
	fd.setMode(FileDialog.SAVE);
	fd.setFilenameFilter(new SuffixFilenameFilter(extension));
	fd.pack();
	fd.setLocationRelativeTo(null);
	fd.setVisible(true);

	String s = fd.getFile();
	if(s==null)
		return null;
	
	if(s.toLowerCase().endsWith("."+extension)) {
		return new File(fd.getDirectory() + s);
	}
	
	return new File(fd.getDirectory() + fd.getFile()+"."+extension);
}
 
开发者ID:mickleness,项目名称:pumpernickel,代码行数:22,代码来源:FileDialogUtils.java

示例7: showSaveDialog

import java.awt.FileDialog; //导入方法依赖的package包/类
protected File showSaveDialog() {
	FileDialog fd = new FileDialog(frame);
	fd.setMode(FileDialog.SAVE);
	fd.setFilenameFilter(new SuffixFilenameFilter("mov"));
	fd.setTitle("Save MOV File");
	fd.pack();
	fd.setLocationRelativeTo(frame);
	fd.setVisible(true);
	if(fd.getFile()==null)
		throw new UserCancelledException();
	String filepath = fd.getDirectory() + fd.getFile();
	if(!filepath.toLowerCase().endsWith(".mov")) {
		filepath += ".mov";
	}
	return new File(filepath);
}
 
开发者ID:mickleness,项目名称:pumpernickel,代码行数:17,代码来源:ScreenCaptureDemo.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包/类
/** This captures a File's icon and saves it as a PNG.
 * This is tested on Mac; I'm not sure how it will perform
 * on Windows. You may need to modify the icon size. As of this
 * writing on Mac: you can pass most any Dimension object and
 * the icon will scale upwards safely.
 */
public static void main(String[] args) throws IOException {
	FileDialog fd = new FileDialog(new Frame());
	fd.pack();
	fd.setVisible(true);
	File f = new File(fd.getDirectory()+fd.getFile());
	Icon icon = getIcon(f);
	icon = new ScaledIcon(icon, 24, 24);
	BufferedImage bi = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_INT_ARGB);
	Graphics2D g = bi.createGraphics();
	icon.paintIcon(null, g, 0, 0);
	g.dispose();
	File f2 = new File(f.getParentFile(), f.getName()+".png");
	if(f2.exists())
		System.exit(1);
	ImageIO.write(bi, "png", f2);
	System.exit(0);;
}
 
开发者ID:mickleness,项目名称:pumpernickel,代码行数:24,代码来源:FileIcon.java

示例10: loadJar

import java.awt.FileDialog; //导入方法依赖的package包/类
public void loadJar() throws IOException {
	FileDialog fd = new FileDialog(new Frame());
	fd.setFilenameFilter(new SuffixFilenameFilter("jar"));
	fd.pack();
	fd.setVisible(true);
	if(fd.getFile()==null) return;
	File jarFile = new File(fd.getDirectory()+fd.getFile());
	try(ZipFile zf = new ZipFile(jarFile)) {
		try(InputStream in = zf.getInputStream(new ZipEntry(KEY_SETUP_ENTRY))) {
			if(in==null) throw new IOException("This jar does not appear to be built with a recent version of JarWriterApp.");
			ContainerProperties p = new ContainerProperties();
			p.load(in);
			p.install(getContentPane(), null);
		}
		zf.close();
	}
}
 
开发者ID:mickleness,项目名称:pumpernickel,代码行数:18,代码来源:JarWriterApp.java

示例11: 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

示例12: 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

示例13: saveConsole

import java.awt.FileDialog; //导入方法依赖的package包/类
private void saveConsole(java.awt.event.ActionEvent evt) {
	String text = mainTextArea.getText();

	FileDialog fc = new FileDialog(this.getFrame(),
			"Save ProtTest console", FileDialog.SAVE);
	fc.setDirectory(System.getProperty("user.dir"));
	fc.setVisible(true);

	String dataFileName = fc.getFile();
	try {
		File f = new File(dataFileName);
		FileWriter fw = new FileWriter(f);
		fw.write(text);
		fw.close();
	} catch (IOException ex) {
		Logger.getLogger(XProtTestView.class.getName()).log(Level.SEVERE,
				null, ex);
	}
}
 
开发者ID:ddarriba,项目名称:prottest3,代码行数:20,代码来源:XProtTestView.java

示例14: doSaveDisk

import java.awt.FileDialog; //导入方法依赖的package包/类
private void doSaveDisk()
{
    FileDialog fd = new FileDialog(getFrame(), "Save Script", FileDialog.SAVE);
    fd.setDirectory(RuntimeLogic.getProp("script.file.dir"));
    fd.setFile(RuntimeLogic.getProp("script.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
    {
        ScriptLogic.saveScript(mRuntime, new File(historyFile));
        RuntimeLogic.setProp("script.file.dir", fd.getDirectory());
        RuntimeLogic.setProp("script.file.file", fd.getFile());
    }
    catch (IOException e)
    {
        JOptionPane.showMessageDialog(this, e.getLocalizedMessage(), "Error reading "+historyFile, JOptionPane.ERROR_MESSAGE);
    }
}
 
开发者ID:jjaquinta,项目名称:EchoSim,代码行数:23,代码来源:ScriptPanel.java

示例15: 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


注:本文中的java.awt.FileDialog.getFile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。