介绍
FileDialog的控制是指一个对话窗口,用户可以从中选择一个文件。
类的声明
以下是声明为java.awt.FileDialog类:
public class FileDialog extends Dialog
字段域
以下java.awt.image类的字段:
- 
		
static int LOAD -- 此常数的值指示文件对话框窗口的目的是找到要从中读取数据的文件。
 - 
		
static int SAVE -- 这个常量值表示,这样做的目的是要找到一个文件,写文件对话框窗口。
 
类的构造函数
| S.N. | 构造函数& 说明 | 
|---|---|
| 1 | 
				FileDialog(Dialog parent)  Creates a file dialog for loading a file.  | 
		
| 2 | 
				FileDialog(Dialog parent, String title) Creates a file dialog window with the specified title for loading a file.  | 
		
| 3 | 
				FileDialog(Dialog parent, String title, int mode)  Creates a file dialog window with the specified title for loading or saving a file.  | 
		
| 4 | 
				FileDialog(Frame parent) Creates a file dialog for loading a file.  | 
		
| 5 | 
				FileDialog(Frame parent, String title)  Creates a file dialog window with the specified title for loading a file.  | 
		
| 6 | 
				FileDialog(Frame parent, String title, int mode)  Creates a file dialog window with the specified title for loading or saving a file.  | 
		
类方法
| S.N. | 方法&说明 | 
|---|---|
| 1 | 
				void addNotify()  Creates the file dialog's peer.  | 
		
| 2 | 
				String getDirectory()  Gets the directory of this file dialog.  | 
		
| 3 | 
				String getFile()  Gets the selected file of this file dialog.  | 
		
| 4 | 
				FilenameFilter getFilenameFilter()  Determines this file dialog's filename filter.  | 
		
| 5 | 
				int getMode()  Indicates whether this file dialog box is for loading from a file or for saving to a file.  | 
		
| 6 | 
				protected String paramString()  Returns a string representing the state of this FileDialog window.  | 
		
| 7 | 
				void setDirectory(String dir)  Sets the directory of this file dialog window to be the specified directory.  | 
		
| 8 | 
				void setFile(String file)  Sets the selected file for this file dialog window to be the specified file.  | 
		
| 9 | 
				void setFilenameFilter(FilenameFilter filter)  Sets the filename filter for this file dialog window to the specified filter.  | 
		
| 10 | 
				void setMode(int mode)  Sets the mode of the file dialog.  | 
		
继承的方法
这个类继承的方法从以下类:
- 
		
java.awt.Dialog
 - 
		
java.awt.Window
 - 
		
java.awt.Component
 - 
		
java.lang.Object
 
Button 实例
选择使用任何编辑器创建以下java程序D:/ > AWT > com > zaixian > gui >
AwtControlDemopackage com.zaixian.gui; import java.awt.*; import java.awt.event.*; public class AwtControlDemo { private Frame mainFrame; private Label headerLabel; private Label statusLabel; private Panel controlPanel; public AwtControlDemo(){ prepareGUI(); } public static void main(String[] args){ AwtControlDemo awtControlDemo = new AwtControlDemo(); awtControlDemo.showFileDialogDemo(); } private void prepareGUI(){ mainFrame = new Frame("Java AWT Examples - www.xuhuhu.com"); mainFrame.setSize(400,400); mainFrame.setLayout(new GridLayout(3, 1)); mainFrame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent windowEvent){ System.exit(0); } }); headerLabel = new Label(); headerLabel.setAlignment(Label.CENTER); statusLabel = new Label(); statusLabel.setAlignment(Label.CENTER); statusLabel.setSize(350,100); controlPanel = new Panel(); controlPanel.setLayout(new FlowLayout()); mainFrame.add(headerLabel); mainFrame.add(controlPanel); mainFrame.add(statusLabel); mainFrame.setVisible(true); } private void showFileDialogDemo(){ headerLabel.setText("Control in action: FileDialog"); final FileDialog fileDialog = new FileDialog(mainFrame,"Select file"); Button showFileDialogButton = new Button("Open File"); showFileDialogButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { fileDialog.setVisible(true); statusLabel.setText("File Selected :" + fileDialog.getDirectory() + fileDialog.getFile()); } }); controlPanel.add(showFileDialogButton); mainFrame.setVisible(true); } }
编译程序,使用命令提示符。到 D:/ > AWT 然后键入以下命令。
D:AWT>javac comzaixianguiAwtControlDemo.java
如果没有错误出现,这意味着编译成功。使用下面的命令来运行程序。
D:AWT>java com.zaixian.gui.AwtControlDemo
验证下面的输出
						上一篇:
								AWT Dialog类
												下一篇:
								AWT事件处理
												
						
						
					
					
					