我正在尝试从菜单按钮打开文件,但我无法找到合适的方法来使用动作侦听器执行此操作。我需要对此代码进行哪些补充才能做到这一点?
private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
int returnValue = openFileChooser.showOpenDialog(this);
if (returnValue == JFileChooser.APPROVE_OPTION){
JOptionPane.showMessageDialog(null, "This a vaild file",
"Display Message",
JOptionPane.INFORMATION_MESSAGE);
}
else {
JOptionPane.showMessageDialog(null, "No file was selected",
"Display Message",
JOptionPane.INFORMATION_MESSAGE);
}
}