我试着理解"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());
}
}发布于 2015-12-22 07:32:09
请参阅此API的JavaDocs
public int showSaveDialog(Component parent) throws HeadlessException弹出“保存文件”文件选择器对话框。请注意,显示在“批准”按钮中的文本由L&F参数: parent -对话框的父组件可以确定为空;有关详细信息,请参见showDialog :弹出时文件选择器的返回状态:
在这里可以找到JavaDocs:
https://stackoverflow.com/questions/34410485
复制相似问题