У меня есть способ загрузить файл клиента, выбрав его в диалоговом окне «Открыть файл», и он работает, за исключением тех случаев, когда я нажимаю кнопку «Отмена». Он по-прежнему загружает выбранный файл, даже если я нажму кнопку «Отмена». Я хочу загрузить пользовательское исключение, если я нажму кнопку «Отмена». Любая помощь в том, как реализовать пользовательское исключение в моем методе, пожалуйста? БлагодаряThrow and Catch Custom Exception
private void loadCustomerActionPerformed(java.awt.event.ActionEvent evt) {
Customer customerfile = null;
try {
final JFileChooser chooser = new JFileChooser("Customers/");
int chooserOption = chooser.showOpenDialog(null);
chooserOption = JFileChooser.APPROVE_OPTION;
File file = chooser.getSelectedFile();
ObjectInputStream in = new ObjectInputStream(
new FileInputStream(file)
);
customerfile = (Customer) in .readObject();
custnameTF.setText(customerfile.getPersonName());
custsurnameTF.setText(customerfile.getPersonSurname());
custidTF.setText(customerfile.getPersonID());
custpassidTF.setText(customerfile.getPassaportID());
customertellTF.setText(customerfile.getPersonTel());
customermobTF.setText(customerfile.getPersonMob());
consnameTF.setText(customerfile.getConsultantname());
conssurnameTF.setText(customerfile.getConsultantsurname());
considTF.setText(customerfile.getConsulid());
in .close();
} catch (IOException ex) {
System.out.println("Error Loading File" + ex.getMessage());
} catch (ClassNotFoundException ex) {
System.out.println("Error Loading Class");
} finally {
System.out.println("Customer Loaded");
}
}
Пожалуйста, не используйте фрагменты Javascript для Java. –