本文整理匯總了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);
}
}