下面列出了java.awt.FileDialog#dispose ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* 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);
}
}
/**
* 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);
}
}
/**
* 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);
}
}
/**
* 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);
}
}
/**
* 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);
}
}
/**
* 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);
}
}
/**
* 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);
}
}
/**
* 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);
}
}
/**
* 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);
}
}
/**
* 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);
}
}
/**
* 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);
}
}
/**
* 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);
}
}
/**
* 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);
}
}