[英]How to understand jFileChooser1.showSaveDialog(this) == JFileChooser.APPROVE_OPTION
我尝试了解“ jFileChooser1.showSaveDialog(this) == JFileChooser.APPROVE_OPTION
”是什么意思?
我认为jFileChooser1.showSaveDialog(this)
返回一个SaveDialog
但JFileChooser.APPROVE_OPTION
返回yes
或ok
。 他们如何平等?
private void save() {
if (jFileChooser1.showSaveDialog(this) ==
JFileChooser.APPROVE_OPTION) {
save(jFileChooser1.getSelectedFile());
}
}
/** Save file with specified File instance */
private void save(File file) {
try {
// Write the text in jta to the specified file
BufferedOutputStream out = new BufferedOutputStream(
new FileOutputStream(file));
byte[] b = (jta.getText()).getBytes();
out.write(b, 0, b.length);
out.close();
// Display the status of the save file operation in jlblStatus
jlblStatus.setText(file.getName() + " Saved ");
}
catch (IOException ex) {
jlblStatus.setText("Error saving " + file.getName());
}
}
有关此API,请参考JavaDocs
public int showSaveDialog(Component parent) throws HeadlessException
弹出“保存文件”文件选择器对话框。 请注意,批准按钮中显示的文本由L&F确定。 参数:parent-对话框的父组件,可以为null;否则为null。 有关详细信息,请参见showDialog。返回:弹出窗口中文件选择器的返回状态:
JavaDocs可以在这里找到:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.