本文整理汇总了Java中java.awt.FileDialog.addWindowListener方法的典型用法代码示例。如果您正苦于以下问题:Java FileDialog.addWindowListener方法的具体用法?Java FileDialog.addWindowListener怎么用?Java FileDialog.addWindowListener使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.FileDialog
的用法示例。
在下文中一共展示了FileDialog.addWindowListener方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: displaySaveAsDialog
import java.awt.FileDialog; //导入方法依赖的package包/类
/**
* perform SAVE AS
*/
void displaySaveAsDialog(int nextEvent) {
// pop up a dialog box for the user to enter a filename.
FileDialog fd = new FileDialog
(tw, PolicyTool.getMessage("Save.As"), FileDialog.SAVE);
fd.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
e.getWindow().setVisible(false);
}
});
fd.setVisible(true);
// see if the user hit cancel
if (fd.getFile() == null ||
fd.getFile().equals(""))
return;
// get the entered filename
File saveAsFile = new File(fd.getDirectory(), fd.getFile());
String filename = saveAsFile.getPath();
fd.dispose();
try {
// save the policy entries to a file
tool.savePolicy(filename);
// display status
MessageFormat form = new MessageFormat(PolicyTool.getMessage
("Policy.successfully.written.to.filename"));
Object[] source = {filename};
tw.displayStatusDialog(null, form.format(source));
// display the new policy filename
JTextField newFilename = (JTextField)tw.getComponent
(ToolWindow.MW_FILENAME_TEXTFIELD);
newFilename.setText(filename);
tw.setVisible(true);
// now continue with the originally requested command
// (QUIT, NEW, or OPEN)
userSaveContinue(tool, tw, this, nextEvent);
} catch (FileNotFoundException fnfe) {
if (filename == null || filename.equals("")) {
tw.displayErrorDialog(null, new FileNotFoundException
(PolicyTool.getMessage("null.filename")));
} else {
tw.displayErrorDialog(null, fnfe);
}
} catch (Exception ee) {
tw.displayErrorDialog(null, ee);
}
}