JavaTM 2 Platform
Standard Ed. 6

java.awt
类 FileDialog

java.lang.Object
  继承者 java.awt.Component
      继承者 java.awt.Container
          继承者 java.awt.Window
              继承者 java.awt.Dialog
                  继承者 java.awt.FileDialog
所有已实现的接口:
ImageObserver, MenuContainer, Serializable, Accessible

public class FileDialog
extends Dialog

FileDialog 类显示一个对话框窗口,用户可以从中选择文件。

由于它是一个模式对话框,当应用程序调用其 show 方法来显示对话框时,它将阻塞其余应用程序,直到用户选择一个文件。

从以下版本开始:
JDK1.0
另请参见:
Window.show(), 序列化表格

嵌套类摘要
 
从类 java.awt.Dialog 继承的嵌套类/接口
Dialog.AccessibleAWTDialog, Dialog.ModalExclusionType, Dialog.ModalityType
 
从类 java.awt.Window 继承的嵌套类/接口
Window.AccessibleAWTWindow
 
从类 java.awt.Container 继承的嵌套类/接口
Container.AccessibleAWTContainer
 
从类 java.awt.Component 继承的嵌套类/接口
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
字段摘要
static int LOAD
          此常量值指示文件对话框窗口的作用是查找要读取的文件。
static int SAVE
          此常量值指示文件对话框窗口的作用是查找要写入的文件。
 
从类 java.awt.Dialog 继承的字段
DEFAULT_MODALITY_TYPE
 
从类 java.awt.Component 继承的字段
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
从接口 java.awt.image.ImageObserver 继承的字段
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
构造方法摘要
FileDialog(Dialog parent)
          创建一个文件对话框,用于加载文件。
FileDialog(Dialog parent, String title)
          创建一个具有指定标题的文件对话框,用于加载文件。
FileDialog(Dialog parent, String title, int mode)
          创建一个具有指定标题的文件对话框窗口,用于加载或保存文件。
FileDialog(Frame parent)
          创建一个文件对话框,用于加载文件。
FileDialog(Frame parent, String title)
          创建一个具有指定标题的文件对话框窗口,用于加载文件。
FileDialog(Frame parent, String title, int mode)
          创建一个具有指定标题的文件对话框窗口,用于加载或保存文件。
 
方法摘要
 void addNotify()
          创建文件对话框的同位体。
 String getDirectory()
          获取此文件对话框的目录。
 String getFile()
          获取此文件对话框的选定文件。
 FilenameFilter getFilenameFilter()
          确定此文件对话框的文件名过滤器。
 int getMode()
          指示此文件对话框是用于从文件加载内容还是将内容保存到文件。
protected  String paramString()
          返回表示此 FileDialog 窗口状态的字符串。
 void setDirectory(String dir)
          将此文件对话框窗口的目录设置为指定目录。
 void setFile(String file)
          将此文件对话框窗口的选定文件设置为指定文件。
 void setFilenameFilter(FilenameFilter filter)
          将此文件对话框窗口的文件名过滤器设置为指定的过滤器。
 void setMode(int mode)
          设置文件对话框的模式。
 
从类 java.awt.Dialog 继承的方法
getAccessibleContext, getModalityType, getTitle, hide, isModal, isResizable, isUndecorated, setModal, setModalityType, setResizable, setTitle, setUndecorated, setVisible, show, toBack
 
从类 java.awt.Window 继承的方法
addPropertyChangeListener, addPropertyChangeListener, addWindowFocusListener, addWindowListener, addWindowStateListener, applyResourceBundle, applyResourceBundle, createBufferStrategy, createBufferStrategy, dispose, getBufferStrategy, getFocusableWindowState, getFocusCycleRootAncestor, getFocusOwner, getFocusTraversalKeys, getGraphicsConfiguration, getIconImages, getInputContext, getListeners, getLocale, getModalExclusionType, getMostRecentFocusOwner, getOwnedWindows, getOwner, getOwnerlessWindows, getToolkit, getWarningString, getWindowFocusListeners, getWindowListeners, getWindows, getWindowStateListeners, isActive, isAlwaysOnTop, isAlwaysOnTopSupported, isFocusableWindow, isFocusCycleRoot, isFocused, isLocationByPlatform, isShowing, pack, postEvent, processEvent, processWindowEvent, processWindowFocusEvent, processWindowStateEvent, removeNotify, removeWindowFocusListener, removeWindowListener, removeWindowStateListener, reshape, setAlwaysOnTop, setBounds, setBounds, setCursor, setFocusableWindowState, setFocusCycleRoot, setIconImage, setIconImages, setLocationByPlatform, setLocationRelativeTo, setMinimumSize, setModalExclusionType, setSize, setSize, toFront
 
从类 java.awt.Container 继承的方法
add, add, add, add, add, addContainerListener, addImpl, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalPolicy, getInsets, getLayout, getMaximumSize, getMinimumSize, getMousePosition, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paint, paintComponents, preferredSize, print, printComponents, processContainerEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, setLayout, transferFocusBackward, transferFocusDownCycle, update, validate, validateTree
 
从类 java.awt.Component 继承的方法
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resize, resize, setBackground, setComponentOrientation, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setName, setPreferredSize, show, size, toString, transferFocus, transferFocusUpCycle
 
从类 java.lang.Object 继承的方法
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

字段详细信息

LOAD

public static final int LOAD
此常量值指示文件对话框窗口的作用是查找要读取的文件。

另请参见:
常量字段值

SAVE

public static final int SAVE
此常量值指示文件对话框窗口的作用是查找要写入的文件。

另请参见:
常量字段值
构造方法详细信息

FileDialog

public FileDialog(Frame parent)
创建一个文件对话框,用于加载文件。文件对话框的标题最初是空的。这是 FileDialog(parent, "", LOAD) 的一个便捷方法。

参数:
parent - 对话框的所有者
从以下版本开始:
JDK1.1

FileDialog

public FileDialog(Frame parent,
                  String title)
创建一个具有指定标题的文件对话框窗口,用于加载文件。显示的文件是当前目录中的文件。这是 FileDialog(parent, title, LOAD) 的一个便捷方法。

参数:
parent - 对话框的所有者
title - 对话框的标题

FileDialog

public FileDialog(Frame parent,
                  String title,
                  int mode)
创建一个具有指定标题的文件对话框窗口,用于加载或保存文件。

如果 mode 的值为 LOAD,那么文件对话框将查找要读取的文件,所显示的文件是当前目录中的文件。如果 mode 的值为 SAVE,则文件对话框将查找要写入文件的位置。

参数:
parent - 对话框的所有者
title - 对话框的标题
mode - 对话框的模式,可以是 FileDialog.LOADFileDialog.SAVE
抛出:
IllegalArgumentException - 如果提供了非法的文件对话框模式
另请参见:
LOAD, SAVE

FileDialog

public FileDialog(Dialog parent)
创建一个文件对话框,用于加载文件。文件对话框的标题最初是空的。这是 FileDialog(parent, "", LOAD) 的一个便捷方法。

参数:
parent - 对话框的所有者
抛出:
IllegalArgumentException - 如果 parentGraphicsConfiguration 不是来自屏幕设备;
IllegalArgumentException - 如果 parentnull;当 GraphicsEnvironment.isHeadless 返回 true 时始终抛出此异常
从以下版本开始:
1.5
另请参见:
GraphicsEnvironment.isHeadless()

FileDialog

public FileDialog(Dialog parent,
                  String title)
创建一个具有指定标题的文件对话框,用于加载文件。显示的文件是当前目录中的文件。这是 FileDialog(parent, title, LOAD) 的一个便捷方法。

参数:
parent - 对话框的所有者
title - 对话框的标题;接受 null 值时不会抛出 NullPointerException
抛出:
IllegalArgumentException - 如果 parentGraphicsConfiguration 不是来自屏幕设备;
IllegalArgumentException - 如果 parentnull;当 GraphicsEnvironment.isHeadless 返回 true 时始终抛出此异常
从以下版本开始:
1.5
另请参见:
GraphicsEnvironment.isHeadless()

FileDialog

public FileDialog(Dialog parent,
                  String title,
                  int mode)
创建一个具有指定标题的文件对话框窗口,用于加载或保存文件。

如果 mode 的值为 LOAD,那么文件对话框将查找要读取的文件,所显示的文件是当前目录中的文件。如果 mode 的值为 SAVE,则文件对话框将查找要写入文件的位置。

参数:
parent - 对话框的所有者
title - 对话框的标题;接受 null 值时不会抛出 NullPointerException
mode - 对话框的模式,FileDialog.LOADFileDialog.SAVE
抛出:
IllegalArgumentException - 如果提供了非法的文件对话框模式;
IllegalArgumentException - 如果 parentGraphicsConfiguration 不是来自屏幕设备;
IllegalArgumentException - 如果 parentnull;当 GraphicsEnvironment.isHeadless 返回 true 时始终抛出此异常
从以下版本开始:
1.5
另请参见:
GraphicsEnvironment.isHeadless(), LOAD, SAVE
方法详细信息

addNotify

public void addNotify()
创建文件对话框的同位体。同位体允许我们更改文件对话框的外观而不更改其功能。

覆盖:
Dialog 中的 addNotify
另请参见:
Component.isDisplayable(), Window.removeNotify()

getMode

public int getMode()
指示此文件对话框是用于从文件加载内容还是将内容保存到文件。

返回:
文件对话框窗口的模式,可以是 FileDialog.LOADFileDialog.SAVE
另请参见:
LOAD, SAVE, setMode(int)

setMode

public void setMode(int mode)
设置文件对话框的模式。如果 mode 不是一个合法值,则抛出一个异常,并且不设置 mode

参数:
mode - 文件对话框的模式,可以是 FileDialog.LOADFileDialog.SAVE
抛出:
IllegalArgumentException - 如果提供了非法的文件对话框模式
从以下版本开始:
JDK1.1
另请参见:
LOAD, SAVE, getMode()

getDirectory

public String getDirectory()
获取此文件对话框的目录。

返回:
FileDialog 的目录(可能为 null 或无效)
另请参见:
setDirectory(java.lang.String)

setDirectory

public void setDirectory(String dir)
将此文件对话框窗口的目录设置为指定目录。指定 null 或无效目录意味着指定由实现所定义的默认值。但是,在用户选择一个文件之前,此默认值不会被实现。在此之前,getDirectory() 将返回传递到此方法的值。

指定 "" 作为目录,完全等同于指定 null 作为目录。

参数:
dir - 指定的目录
另请参见:
getDirectory()

getFile

public String getFile()
获取此文件对话框的选定文件。如果用户选择 CANCEL,则返回文件为 null

返回:
此文件对话框窗口当前所选择的文件;如果没有文件被选择,则返回 null
另请参见:
setFile(java.lang.String)

setFile

public void setFile(String file)
将此文件对话框窗口的选定文件设置为指定文件。如果这么设置,那么在文件对话框窗口第一次显示之前,此文件就成为默认文件。

指定 "" 作为文件,完全等同于指定 null 作为文件。

参数:
file - 正被设置的文件 set
另请参见:
getFile()

getFilenameFilter

public FilenameFilter getFilenameFilter()
确定此文件对话框的文件名过滤器。文件名过滤器允许用户指定哪个文件出现在文件对话框窗口。Microsoft Windows 的文件名过滤器在 Sun 的参考实现中不起作用。

返回:
此文件对话框的文件名过滤器
另请参见:
FilenameFilter, setFilenameFilter(java.io.FilenameFilter)

setFilenameFilter

public void setFilenameFilter(FilenameFilter filter)
将此文件对话框窗口的文件名过滤器设置为指定的过滤器。Microsoft Windows 的文件名过滤器在 Sun 的参考实现中不起作用。

参数:
filter - 指定的过滤器
另请参见:
FilenameFilter, getFilenameFilter()

paramString

protected String paramString()
返回表示此 FileDialog 窗口状态的字符串。此方法仅在进行调试的时候使用,对于不同的实现,返回的字符串的内容和格式可能有所不同。返回的字符串可能为空,但不可能为 null

覆盖:
Dialog 中的 paramString
返回:
此文件对话框窗口的参数字符串

JavaTM 2 Platform
Standard Ed. 6

提交错误或意见
有关更多的 API 参考资料和开发人员文档,请参阅 Java 2 SDK SE 开发人员文档。该文档包含更详细的、面向开发人员的描述,以及总体概述、术语定义、使用技巧和工作代码示例。

版权所有 2004 Sun Microsystems, Inc. 保留所有权利。 请遵守许可证条款。另请参阅文档重新分发政策