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


Java FileDialog類代碼示例

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


FileDialog類屬於java.awt包,在下文中一共展示了FileDialog類的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包/類
/**
 * Show an open dialog with a file chooser set up according to the
 * parameters of this builder.
 * @return A file if the user clicks the accept button and a file or
 * folder was selected at the time the user clicked cancel.
 */
public File showOpenDialog() {
    JFileChooser chooser = createFileChooser();
    if( Boolean.getBoolean("nb.native.filechooser") ) { //NOI18N
        FileDialog fileDialog = createFileDialog( chooser.getCurrentDirectory() );
        if( null != fileDialog ) {
            return showFileDialog(fileDialog, FileDialog.LOAD );
        }
    }
    chooser.setMultiSelectionEnabled(false);
    int dlgResult = chooser.showOpenDialog(findDialogParent());
    if (JFileChooser.APPROVE_OPTION == dlgResult) {
        File result = chooser.getSelectedFile();
        if (result != null && !result.exists()) {
            result = null;
        }
        return result;
    } else {
        return null;
    }

}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:28,代碼來源:FileChooserBuilder.java

示例4: showSaveDialog

import java.awt.FileDialog; //導入依賴的package包/類
/**
 * Show a save dialog with the file chooser set up according to the
 * parameters of this builder.
 * @return A file if the user clicks the accept button and a file or
 * folder was selected at the time the user clicked cancel.
 */
public File showSaveDialog() {
    JFileChooser chooser = createFileChooser();
    if( Boolean.getBoolean("nb.native.filechooser") ) { //NOI18N
        FileDialog fileDialog = createFileDialog( chooser.getCurrentDirectory() );
        if( null != fileDialog ) {
            return showFileDialog( fileDialog, FileDialog.SAVE );
        }
    }
    int result = chooser.showSaveDialog(findDialogParent());
    if (JFileChooser.APPROVE_OPTION == result) {
        return chooser.getSelectedFile();
    } else {
        return null;
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:22,代碼來源:FileChooserBuilder.java

示例5: createFileDialog

import java.awt.FileDialog; //導入依賴的package包/類
private FileDialog createFileDialog( File currentDirectory ) {
    if( badger != null )
        return null;
    if( !Boolean.getBoolean("nb.native.filechooser") )
        return null;
    if( dirsOnly && !BaseUtilities.isMac() )
        return null;
    Component parentComponent = findDialogParent();
    Frame parentFrame = (Frame) SwingUtilities.getAncestorOfClass(Frame.class, parentComponent);
    FileDialog fileDialog = new FileDialog(parentFrame);
    if (title != null) {
        fileDialog.setTitle(title);
    }
    if( null != currentDirectory )
        fileDialog.setDirectory(currentDirectory.getAbsolutePath());
    return fileDialog;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:18,代碼來源:FileChooserBuilder.java

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

示例7: ExportMenuItem

import java.awt.FileDialog; //導入依賴的package包/類
public ExportMenuItem(final FlagFrame frame) {
	setText("Export...");
	if (!OSUtils.isMacOS()) setMnemonic(KeyEvent.VK_E);
	setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputUtils.META_MASK));
	if (frame == null) {
		setEnabled(false);
	} else {
		addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent event) {
				FileDialog fd = new FileDialog(frame, "Export", FileDialog.SAVE);
				fd.setVisible(true);
				if (fd.getDirectory() == null || fd.getFile() == null) return;
				File file = new File(fd.getDirectory(), fd.getFile());
				new ExportDialog(
					frame, frame.getParentFile(), frame.getFlag(), file,
					frame.getViewerWidth(), frame.getViewerHeight(), frame.getGlaze()
				).setVisible(true);
			}
		});
	}
}
 
開發者ID:kreativekorp,項目名稱:vexillo,代碼行數:22,代碼來源:ExportMenuItem.java

示例8: OpenMenuItem

import java.awt.FileDialog; //導入依賴的package包/類
public OpenMenuItem() {
	setText("Open...");
	if (!OSUtils.isMacOS()) setMnemonic(KeyEvent.VK_O);
	setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, InputUtils.META_MASK));
	addActionListener(new ActionListener() {
		public void actionPerformed(ActionEvent event) {
			FileDialog fd = new FileDialog(new Frame(), "Open", FileDialog.LOAD);
			fd.setVisible(true);
			if (fd.getDirectory() == null || fd.getFile() == null) return;
			File file = new File(fd.getDirectory(), fd.getFile());
			try {
				FileInputStream in = new FileInputStream(file);
				Flag flag = FlagParser.parse(file.getName(), in);
				in.close();
				String title = file.getName();
				if (flag.getName() != null) title += ": " + flag.getName();
				FlagFrame frame = new FlagFrame(title, file, flag);
				frame.setVisible(true);
			} catch (Exception e) {
				JOptionPane.showMessageDialog(null, "Error: " + e.getMessage(), "Open", JOptionPane.ERROR_MESSAGE);
			}
		}
	});
}
 
開發者ID:kreativekorp,項目名稱:vexillo,代碼行數:25,代碼來源:OpenMenuItem.java

示例9: showNativeDialog

import java.awt.FileDialog; //導入依賴的package包/類
private void showNativeDialog() {
    String dirname = fd.getDirectory();
    // File path has a priority against directory path.
    String filename = fd.getFile();
    if (filename != null) {
        final File file = new File(filename);
        if (fd.getMode() == FileDialog.LOAD
            && dirname != null
            && file.getParent() == null) {
            // File path for gtk_file_chooser_set_filename.
            filename = dirname + (dirname.endsWith(File.separator) ? "" :
                                          File.separator) + filename;
        }
        if (fd.getMode() == FileDialog.SAVE && file.getParent() != null) {
            // Filename for gtk_file_chooser_set_current_name.
            filename = file.getName();
            // Directory path for gtk_file_chooser_set_current_folder.
            dirname = file.getParent();
        }
    }
    run(fd.getTitle(), fd.getMode(), dirname, filename,
        fd.getFilenameFilter(), fd.isMultipleMode(), fd.getX(), fd.getY());
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:24,代碼來源:GtkFileDialogPeer.java

示例10: init

import java.awt.FileDialog; //導入依賴的package包/類
@Override
public void init() {
    if (OSInfo.getOSType() != OSInfo.OSType.MACOSX) {
        Sysout.createDialogWithInstructions(new String[]{
                "Press PASS, this test is for MacOS X only."});
        return;
    }

    System.setProperty("apple.awt.use-file-dialog-packages", "true");

    setLayout(new GridLayout(1, 1));

    fd = new FileDialog(new Frame(), "Open");
    fd.setDirectory(APPLICATIONS_FOLDER);

    showBtn = new Button("Show File Dialog");
    showBtn.addActionListener(this);
    add(showBtn);
    String[] instructions = {
            "1) Click on 'Show File Dialog' button. A file dialog will come up.",
            "2) Navigate to the Applications folder if not already there",
            "3) Check that the application bundles can be selected and can not be navigated",
            "4) If it's true then the test passed, otherwise it failed."};
    Sysout.createDialogWithInstructions(instructions);
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:26,代碼來源:FileDialogForPackages.java

示例11: init

import java.awt.FileDialog; //導入依賴的package包/類
@Override
public void init() {
    if (OSInfo.getOSType() != OSInfo.OSType.MACOSX) {
        Sysout.createDialogWithInstructions(new String[]{
                "Press PASS, this test is for MacOS X only."});
        return;
    }

    System.setProperty("apple.awt.fileDialogForDirectories", "true");

    setLayout(new GridLayout(1, 1));

    fd = new FileDialog(new Frame(), "Open");

    showBtn = new Button("Show File Dialog");
    showBtn.addActionListener(this);
    add(showBtn);
    String[] instructions = {
            "1) Click on 'Show File Dialog' button. A file dialog will come up.",
            "2) Check that files can't be selected.",
            "3) Check that directories can be selected.",
            "4) Repeat steps 1 - 3 a few times for different files and directories.",
            "5) If it's true then the test passed, otherwise it failed."};
    Sysout.createDialogWithInstructions(instructions);
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:26,代碼來源:FileDialogForDirectories.java

示例12: showNativeDialog

import java.awt.FileDialog; //導入依賴的package包/類
private void showNativeDialog() {
    String dirname = fd.getDirectory();
    // File path has a priority against directory path.
    String filename = fd.getFile();
    if (filename != null) {
        final File file = new File(filename);
        if (fd.getMode() == FileDialog.LOAD
            && dirname != null
            && file.getParent() == null) {
            // File path for gtk_file_chooser_set_filename.
            filename = dirname + (dirname.endsWith(File.separator) ? "" :
                                          File.separator) + filename;
        }
        if (fd.getMode() == FileDialog.SAVE && file.getParent() != null) {
            // Filename for gtk_file_chooser_set_current_name.
            filename = file.getName();
            // Directory path for gtk_file_chooser_set_current_folder.
            dirname = file.getParent();
        }
    }
    if (!quit) {
        run(fd.getTitle(), fd.getMode(), dirname, filename,
                fd.getFilenameFilter(), fd.isMultipleMode(), fd.getX(), fd.getY());
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:26,代碼來源:GtkFileDialogPeer.java

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

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

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


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