allora, seguendo il tuo consiglio ho fatto così:
(e ancora ne devo aggiungere).codice:itemSaveTxt.addActionListener(cal); itemSaveXls.addActionListener(cal); itemPrint.addActionListener(cal); itemAbout.addActionListener(cal); itemSavePdf.addActionListener(cal); itemAuthorsChart.addActionListener(cal); itemEditorsChart.addActionListener(cal); itemSaveXml.addActionListener(cal); itemEsc.addActionListener(cal); // EVENTI BUTTON btnConnect.addActionListener(cal); .................. private class CustomActionListener implements ActionListener { @Override public void actionPerformed(ActionEvent ev) { Object source = ev.getSource(); try { if (source == itemAbout) { FormAbout about = new FormAbout(); about.setVisible(true); } else if (source == itemPrint) { tableData.print(JTable.PrintMode.FIT_WIDTH); } else if (source == itemSaveTxt) { FileChooser fc = new FileChooser(); fc.salvaTxt(tableData); } else if (source == itemSaveXls) { FileChooser fc = new FileChooser(); fc.salvaXls(tableData); } else if (source == itemSavePdf) { FileChooser fc = new FileChooser(); fc.salvaPdf(jsonRead.getAllBooks()); } else if (source == itemAuthorsChart) { FormGraph fg = new FormGraph(UrlAndPath.GRAPH_AUTHORS); fg.setVisible(true); } else if (source == itemEditorsChart) { FormGraph fg = new FormGraph(UrlAndPath.GRAPH_EDITORS); fg.setVisible(true); } else if (source == itemSaveXml) { FileChooser fc = new FileChooser(); fc.salvaXml(tableData); } else if (source == itemEsc) { close(); } else if (source == btnConnect) { createConnection(); } } catch (IOException ex) { JOptionPane.showMessageDialog(null, ex.getMessage()); } catch (WriteException | PrinterException | DocumentException | JAXBException ex) { JOptionPane.showMessageDialog(null, ex.getMessage()); } } }
potrebbe andare?
ho pensato anche di "accorpare" la gestione delle eccezioni qui (visto che parecchi metodi ne lanciano di simili).
potrebbe andare questo approccio o è sbagliato??

Rispondi quotando