本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
}
示例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);
}
}
示例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());
}
}
}
示例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());
}
示例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);
}
}
示例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;
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
示例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);
}